home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / picks / HTTrack / httrack-3.22-3.exe / {app} / src_win / WinHTTrack / Shell.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-30  |  100.6 KB  |  2,910 lines

  1. // Shell.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. // thread windows
  5. #include <process.h>
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. #include "htsbase.h"
  12.  
  13. // Ras
  14. #if USE_RAS 
  15. #include "RasLoad.h"
  16. #endif
  17.  
  18. #include <afxdisp.h>
  19. #include "ras.h"
  20.  
  21. //#include "ShellDoc.h"
  22. //#include "ShellView.h"
  23.  
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29.  
  30. // PATCH-->
  31. // PATCH-->
  32. #include "about.h"
  33. #include "infoend.h"
  34.  
  35. // flag de termination
  36. int termine=0;
  37. int termine_requested=0;
  38. int shell_terminated=0;
  39. int soft_term_requested=0;
  40. FILE* fp_debug=NULL;
  41.  
  42. #include "stdafx.h"
  43. #include "Shell.h"
  44. #include "process.h"
  45. //#include "ShellDoc.h"
  46. //#include "ShellView.h"
  47. //#include "essai.h"
  48. //#include "get.h"
  49. //#include "parameter.h"
  50. extern "C" {
  51.   #include "htssystem.h"
  52. }
  53. #include "Wid1.h"
  54. #include "trans.h"
  55. #include "InfoUrl.h"
  56. //#include "option.h"
  57. //#include "filter.h"
  58. //#include "wizard.h"
  59. //
  60. #include "maintab.h"
  61. //
  62. #include "MemRegister.h"
  63.  
  64. // LANG
  65. #include "newlang.h"
  66.  
  67.  
  68. // PATCH-->
  69. //#include "wizard2.h"
  70. //#include "WizLinks.h"
  71.  
  72. #include "inprogress.h"
  73.  
  74. #include "SYS\TIMEB.H"
  75.  
  76. // htswrap_add
  77. extern "C" {
  78.   #include "htswrap.h"
  79. };
  80.  
  81. // --- --- --- --- Options --- --- --- ---
  82.  
  83. #define MAX_LEN_INPROGRESS 32
  84.  
  85. // lancement en multithread du shell ET de gethostbyname
  86. #define SHELL_MULTITHREAD 1
  87. //#define HTS_XGMETHOD 2    // 1: AfxBeginThread 2: _beginthread
  88. // --- --- --- --- Options --- --- --- ---
  89. //int INREDRAW_LOCKED=0;      // refresh graphique en cours
  90. //int INFILLMEM_LOCKED=0;     // refresh mÈmoire en cours
  91. int HTTRACK_result=0;
  92. //
  93. CInfoUrl* _Cinprogress_inst=NULL;
  94.  
  95. extern HICON httrack_icon;
  96.  
  97. /* Main splitter frame */
  98. #include "DialogContainer.h"
  99. #include "splitter.h"
  100. extern CSplitterFrame* this_CSplitterFrame;
  101.  
  102. /* Main WizTab frame */
  103. #include "WizTab.h"
  104. extern CWizTab* this_CWizTab;
  105. /* Argh - pas de domodal dans des autres threads ?!?! */
  106. char WIZ_question[1000];
  107. char WIZ_reponse[1000];
  108.  
  109.  
  110. // Fonctionnement des THREADS:
  111. //
  112. // principal ---> robot & refresh data (thread 1)
  113. //           ---> refresh graphique    (thread 2)
  114. //           GO!> boucle gestion domodal() et boutons
  115. // arrÍt: principal demande l'arrÍt (termine_requested)
  116. //        thread1 active termine et que thread2 ait fini de refresher
  117. //        thread2 se termine
  118. //        thread1 retourne 0 ‡ hts_loop
  119. //        le robot termine
  120. //        le thread1 active termine, termine le formulaire et se termine
  121. //        principal ayant quittÈ le formulaire affiche le message de fin
  122.  
  123.  
  124. // htslib.c
  125. extern "C" {
  126.   HTSEXT_API void qsec2str(char *st,TStamp t);
  127. }
  128.  
  129. // construction index gÈnÈral
  130. // void Build_TopIndex();
  131.  
  132. void compute_options() ;
  133. char* connversion(char chaine[10000]);
  134. void lance(void);
  135. int check_continue(char* pathlog);
  136. int inprogress_refresh();
  137. //int inprogress_refresh_scan();
  138. void Write_profile(CString path,int load_path);
  139. void Read_profile(CString path,int load_path);
  140.  
  141.  
  142. // dÈja fait mais bon
  143. #define HTS_WIN 1
  144.  
  145. extern "C" {
  146.   #include "htscore.h"
  147. }
  148.  
  149. CString _HTTRACK_VERSION = HTTRACK_VERSION;
  150.  
  151. char LINE[32768];
  152. char OPTIONurl[32000];
  153. char OPTIONfilelist[HTS_URLMAXSIZE*2];
  154. char OPTIONproxy[500];
  155. char OPTIONport[100];
  156. char OPTIONdepth[20];
  157. char OPTIONextdepth[20];
  158. char OPTIONget[10];
  159. //char OPTIONlevel[10];
  160. char OPTIONwhere[8];
  161. char OPTIONmeth[8];
  162. char OPTIONmaxfile[100];
  163. char OPTIONmax[100];
  164. char OPTIONfrag[100];
  165. char OPTIONconn[100];
  166. char OPTIONtog[10];
  167. char OPTIONcache[8];
  168. char OPTIONrobots[8];
  169. char choixdeb[8];
  170. char build[256];
  171. char filtre[32];
  172. char OPTIONhtmlfirst[8];
  173. char OPTIONindex[8];
  174. char OPTIONindex2[8];
  175. char OPTIONdos[8];
  176. char OPTIONtime[20];
  177. char OPTIONrate[20];
  178. char OPTIONhostquit[20];
  179. char OPTIONuser[256];
  180. char OPTIONfooter[256];
  181. char OPTIONlog[8];
  182. char OPTIONtestall[8];
  183. char OPTIONparseall[8];
  184. char OPTIONlink[8];
  185. char OPTIONpath[1000];
  186. char OPTIONretry[16];
  187. char OPTIONerrpage[8];
  188. char OPTIONexternal[8];
  189. char OPTIONnopurge[8];
  190. char OPTIONhidepwd[8];
  191. char OPTIONhidequery[8];
  192. char OPTIONcookies[8];
  193. char OPTIONchecktype[8];
  194. char OPTIONparsejava[8];
  195. char OPTIONCache2[8];
  196. char OPTIONlogtype[8];
  197. char OPTIONnorecatch[8];
  198. char OPTIONtoler[8];
  199. char OPTIONupdhack[8];
  200. char OPTIONhttp10[8];
  201. //-->
  202. char OPTIONwaittime[32];
  203. char OPTIONmaxtime[32];
  204. char OPTIONmaxrate[32];
  205. char OPTIONmaxconn[32];
  206. char OPTIONmaxlinks[32];
  207. char OPTIONhh[32];
  208. char OPTIONmm[32];
  209. char OPTIONss[32];
  210. //
  211. char buff_filtres[8192];
  212. char buff_MIME[8192];
  213. // RAS
  214. char OPTION_RasString[256];
  215. RASDIALPARAMS OPTION_dial;
  216.  
  217. // Fichier tempo
  218. FILE* tmpf=NULL;
  219. MemRegister tmpm;
  220.  
  221. CNewProj* dialog0=NULL;
  222. Wid1* dialog1=NULL;
  223. Ctrans* dialog2=NULL;
  224. //Coption dialog3;
  225. //Cfilter diafiltre;
  226. /*
  227. wizard diawiz;
  228. wizard2 diawiz2;
  229. WizLinks diawiz3;
  230. */
  231. //
  232. CMainTab* maintab=NULL;
  233. CShellApp* CShellApp_app=NULL;
  234.  
  235. #include "infoend.h"
  236. extern Cinfoend* this_Cinfoend;
  237.  
  238.  
  239. // PATCH-->
  240. Cinprogress* inprogress=NULL;
  241.  
  242. // nbre de slides
  243. t_StatsBuffer StatsBuffer[NStatsBuffer];
  244. void* StatsBufferback=NULL;
  245. int StatsBufferback_max=0;
  246. InpInfo SInfo;
  247.  
  248. #if USE_RAS
  249. // Chargement des librairies RAS
  250. CDynamicRAS* LibRas=NULL;
  251. int LibRasUse=0;
  252. //
  253. int connected=0;
  254. int disconnect=0;
  255. HRASCONN conn = NULL;
  256. int has_started=0;
  257. char connected_err[1000]="";
  258. #endif
  259.  
  260. // pour message final
  261. extern char end_mirror_msg[8192];
  262. #include "winhttrack.h"
  263. extern CWinHTTrackApp* this_app;
  264.  
  265.  
  266. // PATCH-->
  267. // PATCH-->
  268. // FIN PATCH
  269.  
  270.  
  271. /////////////////////////////////////////////////////////////////////////////
  272. // CShellApp
  273.  
  274. /*
  275. BEGIN_MESSAGE_MAP(CShellApp, CWinApp)
  276. //{{AFX_MSG_MAP(CShellApp)
  277. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  278. // NOTE - the ClassWizard will add and remove mapping macros here.
  279. //    DO NOT EDIT what you see in these blocks of generated code!
  280. //}}AFX_MSG_MAP
  281. // Standard file based document commands
  282. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  283. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  284. // Standard print setup command
  285. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  286. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  287. END_MESSAGE_MAP()
  288. */
  289.  
  290. /////////////////////////////////////////////////////////////////////////////
  291. // CShellApp construction
  292.  
  293. CShellApp::CShellApp()
  294. {
  295.   // TODO: add construction code here,
  296.   // Place all significant initialization in InitInstance
  297. }
  298.  
  299. /////////////////////////////////////////////////////////////////////////////
  300. // The one and only CShellApp object
  301.  
  302. //CShellApp theApp;
  303.  
  304. /////////////////////////////////////////////////////////////////////////////
  305. // CShellApp initialization
  306.  
  307. UINT RunBackMirror( LPVOID pP ) {
  308.   CShellApp_app->init_lance();
  309.   return 0;
  310. }
  311.  
  312. BOOL LaunchMirror() {
  313.   WHTT_LOCK();
  314.   hts_resetvar();
  315.   WHTT_UNLOCK();
  316.   AfxBeginThread(RunBackMirror,NULL);
  317.   return 0;
  318. }
  319.  
  320. #if 0
  321. BOOL CShellApp::InitInstance()
  322. {
  323.   CShellApp_app=this;
  324.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  325.   
  326.   // Initialize OLE libraries
  327.   /*
  328.   if (!AfxOleInit())
  329.   {
  330.   AfxMessageBox(LANG(LANG_F1));
  331.   return FALSE;
  332.   }
  333.   AfxEnableControlContainer();
  334.   */
  335.   
  336.   // Fixer localisation dans la base de registre
  337.   //SetRegistryKey("WinHTTrack");
  338.   
  339.   // Standard initialization
  340.   // If you are not using these features and wish to reduce the size
  341.   //  of your final executable, you should remove from the following
  342.   //  the specific initialization routines you do not need.
  343.   /*
  344.   #ifdef _AFXDLL
  345.   Enable3dControls();            // Call this when using MFC in a shared DLL
  346.   #else
  347.   Enable3dControlsStatic();    // Call this when linking to MFC statically
  348.   #endif
  349.   */
  350.   
  351.   // Register the application's document templates.  Document templates
  352.   //  serve as the connection between documents, frame windows and views.
  353.   
  354.   // Change the registry key under which our settings are stored.
  355.   // You should modify this string to be something appropriate
  356.   // such as the name of your company or organization.
  357.   //SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  358.   
  359.   //LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  360.   
  361.   // Register the application's document templates.  Document templates
  362.   //  serve as the connection between documents, frame windows and views.
  363.   
  364.   // Parse command line for standard shell commands, DDE, file open
  365.   /*CCommandLineInfo cmdInfo;
  366.   ParseCommandLine(cmdInfo);
  367.   */
  368.   
  369.   _Cinprogress_inst=NULL;
  370.   
  371.   LibRasUse=0;
  372.   
  373.   /*
  374.   #if USE_RAS
  375.   LibRas=new CDynamicRAS();
  376.   if (LibRas->IsRASLoaded()) 
  377.   LibRasUse=1;
  378.   else
  379.   LibRasUse=0;
  380.   #endif
  381.   */
  382.   
  383.   maintab = new CMainTab("WinHTTrack Website Copier");
  384.   
  385.   // PATCH-->
  386.   // ÈxÈcution..
  387.   init_lance();
  388.   
  389.   delete maintab;
  390.   maintab=NULL;
  391.   
  392.   // PATCH-->
  393.   /*
  394.   // Dispatch commands specified on the command line
  395.   if (!ProcessShellCommand(cmdInfo))
  396.         return FALSE;
  397.     
  398.       // The one and only window has been initialized, so show and update it.
  399.       m_pMainWnd->ShowWindow(SW_SHOW);
  400.       m_pMainWnd->UpdateWindow();
  401.   */  
  402.   
  403.   
  404.   return TRUE;
  405. }
  406. #endif
  407.  
  408. // PATCH-->
  409. // routines diverses
  410.  
  411. char* _SN(LLint n) {
  412.   static char str[256];
  413.   str[0]='\0';
  414.   sprintf(str,LLintP,(LLint)n);        /* 64-bit */
  415.   return str;
  416. }
  417.  
  418. // t existe-t-il comme rÈpertoire?
  419. int dir_check(char* t) {
  420.   int dir;
  421.   FILE* fp=fopen(t,"rb");
  422.   dir=(errno==13);  // is directory
  423.   if (fp) fclose(fp);
  424.   return dir;
  425. }
  426.  
  427. void check_temp(char* t,char* s) {
  428.   if (strlen(s)==0)
  429.     if (dir_check(t))
  430.       strcpybuff(s,t);
  431. }
  432.  
  433.  
  434.  
  435. // PATCH-->
  436. // Routines gestion dials
  437. // PatchÈ pour 100% dials
  438.  
  439.  
  440. void CShellApp::init_lance() {
  441.   hts_init();
  442.   htswrap_add("check-link",httrackengine_check);
  443.   htswrap_add("init",httrackengine_init);
  444.   htswrap_add("free",httrackengine_uninit);
  445.   htswrap_add("start",httrackengine_start);
  446.   htswrap_add("end",httrackengine_end);
  447.   htswrap_add("check-html",httrackengine_htmlcheck);
  448.   htswrap_add("change-options",httrackengine_chopt);
  449.   htswrap_add("loop",httrackengine_loop);
  450.   htswrap_add("query",httrackengine_query);
  451.   htswrap_add("query2",httrackengine_query2);
  452.   htswrap_add("query3",httrackengine_query3);
  453.   htswrap_add("pause",httrackengine_pause);
  454.   
  455.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  456.   lance();             // Lancer miroir!
  457.   if (fp_debug) {
  458.     fprintf(fp_debug,"Building top index\r\n");
  459.     fflush(fp_debug);
  460.   }
  461.   Build_TopIndex();
  462. }
  463.  
  464. /* sauver profile */
  465. /* ask: demande confirmation, si cela vaut le coup */
  466. int Save_current_profile(int ask) {
  467.   CString winprofile;
  468.   if (ask) {
  469.     if ((dialog0->GetName().IsEmpty()) && (dialog1->m_urls.IsEmpty()))
  470.       return IDNO;
  471.     int r;
  472.     char msg[256];
  473.     sprintf(msg,"%s?\r\n%s",LANG_SAVEPROJECT,dialog0->GetName());
  474.     if ((r=AfxMessageBox(msg,MB_YESNOCANCEL)) != IDYES)
  475.       return r;
  476.   }
  477.   //
  478.   CWaitCursor wait;
  479.   
  480.   // sauver whtt
  481.   {
  482.     CString st=dialog0->GetBasePath()+dialog0->GetName()+".whtt";
  483.     FILE* fp=fopen(st,"wb");
  484.     if (fp) fclose(fp);
  485.   }
  486.   
  487.   // sauver ini
  488.   winprofile=dialog0->GetPath();
  489.   if (winprofile.GetLength()>0)
  490.     if ((winprofile.Right(1)!="/") && (winprofile.Right(1)!="\\"))
  491.       winprofile+="\\";
  492.     winprofile+="hts-cache\\";
  493.     {
  494.       char tempo[HTS_URLMAXSIZE*2];
  495.       int i;
  496.       strcpybuff(tempo,winprofile);
  497.       for(i=0;i<(int)strlen(tempo);i++)
  498.         if (tempo[i]=='\\')
  499.           tempo[i]='/';              
  500.         structcheck(tempo);
  501.     }
  502.     
  503.     winprofile+="winprofile.ini";
  504.     Write_profile(winprofile,0);
  505.     
  506.     // marquer document comme "sauvÈ"
  507.     if (this_CSplitterFrame)
  508.       this_CSplitterFrame->SetSaved();
  509.     
  510.     return IDYES;
  511. }
  512.  
  513. // reprise possible?
  514. int check_continue(char* pathlog) {
  515.   char path_log[256];
  516.   strcpybuff(path_log,pathlog);
  517.   if (strlen(path_log)>0)
  518.     if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  519.       strcatbuff(path_log,"/");
  520.     if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dÈja un cache prÈcÈdent.. renommer
  521.       //if (fexist(fconcat(path_log,"hts-cache/doit.log"))) {    // un cache est prÈsent
  522.       return 1;
  523.       //}
  524.     }
  525.     if ((fexist(fconcat(path_log,"hts-cache/old.dat"))) && (fexist(fconcat(path_log,"hts-cache/old.ndx")))) {  // il existe dÈja un ancien cache prÈcÈdent.. renommer
  526.       return 1;
  527.     }
  528.     AfxMessageBox(LANG(LANG_F2 /*"There is no cache in the directory indicated\nWinHTTrack can not find any interrupted mirror!"*/),MB_OK+MB_ICONSTOP);
  529.     return 0;
  530. }
  531.  
  532.  
  533. void CShellApp::OptPannel() {
  534.   Write_profile("<mem>",0);       // enregistrer profile dans buffer local
  535.   if (maintab->DoModal()==IDCANCEL) {
  536.     Read_profile("<mem>",0);      // restaurer
  537.   }
  538. }
  539.  
  540.  
  541. #define ADD_MIME_IN_COPT(A) \
  542.   if(strlen(maintab->m_option11.m_ext##A)+strlen(maintab->m_option11.m_mime##A)) { \
  543.   strcatbuff(buff_MIME,"--assume "); \
  544.   strcatbuff(buff_MIME,maintab->m_option11.m_ext##A); \
  545.   strcatbuff(buff_MIME,"="); \
  546.   strcatbuff(buff_MIME,maintab->m_option11.m_mime##A); \
  547.   strcatbuff(buff_MIME," "); \
  548.   } \
  549.   
  550. // parser maintab et calculer options
  551. void compute_options() { 
  552.   CWaitCursor wait;
  553.   
  554.   /* Effacer options */
  555.   LINE[0]
  556.     =OPTIONurl[0]
  557.     =OPTIONfilelist[0]
  558.     =OPTIONproxy[0]
  559.     =OPTIONport[0]
  560.     =OPTIONdepth[0]
  561.     =OPTIONextdepth[0]
  562.     =OPTIONget[0]
  563.     =OPTIONwhere[0]
  564.     =OPTIONmeth[0]
  565.     =OPTIONmaxfile[0]
  566.     =OPTIONmax[0]
  567.     =OPTIONfrag[0]
  568.     =OPTIONconn[0]
  569.     =OPTIONtog[0]
  570.     =OPTIONcache[0]
  571.     =OPTIONrobots[0]
  572.     =choixdeb[0]
  573.     =build[0]
  574.     =filtre[0]
  575.     =OPTIONindex[0]
  576.     =OPTIONindex2[0]
  577.     =OPTIONdos[0]
  578.     =OPTIONtime[0]
  579.     =OPTIONrate[0]
  580.     =OPTIONhostquit[0]
  581.     =OPTIONuser[0]
  582.     =OPTIONfooter[0]
  583.     =OPTIONlog[0]
  584.     =OPTIONtestall[0]
  585.     =OPTIONparseall[0]
  586.     =OPTIONlink[0]
  587.     =OPTIONpath[0]
  588.     =OPTIONretry[0]
  589.     =OPTIONerrpage[0]
  590.     =OPTIONexternal[0]
  591.     =OPTIONnopurge[0]
  592.     =OPTIONhidepwd[0]
  593.     =OPTIONhidequery[0]
  594.     =OPTIONcookies[0]
  595.     =OPTIONchecktype[0]
  596.     =OPTIONparsejava[0]
  597.     =OPTIONCache2[0]
  598.     =OPTIONlogtype[0]
  599.     =OPTIONnorecatch[0]
  600.     =OPTIONtoler[0]
  601.     =OPTIONupdhack[0]
  602.     =OPTIONhttp10[0]
  603.     =OPTIONwaittime[0]
  604.     =OPTIONmaxtime[0]
  605.     =OPTIONmaxrate[0]
  606.     =OPTIONmaxconn[0]
  607.     =OPTIONmaxlinks[0]
  608.     =OPTIONhh[0]
  609.     =OPTIONmm[0]
  610.     =OPTIONss[0]
  611.     =buff_filtres[0]
  612.     =buff_MIME[0]
  613.     =OPTION_RasString[0]
  614.     ='\0';
  615.   /* Effacer options */
  616.   
  617.   // Mode de miroir
  618.   switch(dialog1->m_todo) {
  619.   case CB_ERR: case 0:
  620.     strcpybuff(choixdeb,"w");
  621.     break;
  622.   case 1:
  623.     strcpybuff(choixdeb,"W");
  624.     break;
  625.   case 2:
  626.     strcpybuff(choixdeb,"g");
  627.     break;
  628.   case 3:
  629.     strcpybuff(choixdeb,"Y");
  630.     break;
  631.   case 4:
  632.     strcpybuff(choixdeb,"!");
  633.     break;
  634.   default:
  635.     if (dialog1->m_todo==dialog1->LAST_ACTION)
  636.       strcpybuff(choixdeb,"i");    // reprise
  637.     else
  638.       strcpybuff(choixdeb,"/");    // reprise cache prioritaire
  639.     break;
  640.   }
  641.   
  642.   // URLS
  643.   char trans[50000];
  644.   strcpybuff(trans,"");
  645.   strncatbuff(trans,dialog1->m_urls,30000);
  646.   strcpybuff(OPTIONurl,connversion(trans));
  647.   // --- formation du path
  648.   strcpybuff(OPTIONpath,"\""); strcatbuff(OPTIONpath,dialog0->GetPath0()); strcatbuff(OPTIONpath,"\"");
  649.   strcatbuff(OPTIONpath,",");
  650.   strcatbuff(OPTIONpath,"\""); strcatbuff(OPTIONpath,dialog0->GetPath0()); strcatbuff(OPTIONpath,"\"");
  651.   
  652.   // filelist
  653.   {
  654.     CString st=dialog1->m_filelist;
  655.     st.TrimLeft();
  656.     st.TrimRight();
  657.     strcpybuff(OPTIONfilelist,st);
  658.   }
  659.   
  660.   // stocker Ètat et hh/mm/ss
  661.   strcpybuff(OPTIONhh,dialog2->m_hh);
  662.   strcpybuff(OPTIONmm,dialog2->m_mm);
  663.   strcpybuff(OPTIONss,dialog2->m_ss);
  664.   if (strlen(OPTIONhh)) {    // heure
  665.     int x,y,z;
  666.     sscanf(OPTIONhh,"%d",&x);
  667.     x=min(max(x,0),23);
  668.     sprintf(OPTIONhh,"%d",x);
  669.     //
  670.     sscanf(OPTIONmm,"%d",&y);
  671.     y=min(max(y,0),59);
  672.     sprintf(OPTIONmm,"%d",y);
  673.     //
  674.     sscanf(OPTIONss,"%d",&z);
  675.     z=min(max(z,0),59);
  676.     sprintf(OPTIONss,"%d",z);
  677.     //
  678.     strcpybuff(OPTIONwaittime,"");
  679.     {
  680.       char str[32];
  681.       strcpybuff(OPTIONwaittime,"#u");
  682.       sprintf(str,"%d",x*3600+y*60+z);
  683.       strcatbuff(OPTIONwaittime,str);
  684.     }
  685.   }
  686.   strcpybuff(OPTION_RasString,dialog2->RasString);
  687.   OPTION_dial=dialog2->dial;
  688.   
  689.   if (choixdeb[0]=='/') {
  690.     strcpybuff(OPTIONcache,"C1");      // cache prio
  691.   } else {
  692.     if(!maintab->m_option3.m_cache) 
  693.       strcpybuff(OPTIONcache,"C0"); 
  694.     else 
  695.       strcpybuff(OPTIONcache,"C2");     // cache non prio 
  696.     //OPTIONcache[0]='\0'; 
  697.   }
  698.   
  699.   // ne pas recharger fichiers dÈja pris mais effacÈs
  700.   if(maintab->m_option9.m_norecatch) strcpybuff(OPTIONnorecatch,"%n"); else strcpybuff(OPTIONnorecatch,"");
  701.   
  702.   // proxy
  703.   strcpybuff(OPTIONproxy,maintab->m_option10.m_proxy);
  704.   strcpybuff(OPTIONport,maintab->m_option10.m_port);
  705.   
  706.   //depth
  707.   strcpybuff(OPTIONdepth,maintab->m_option5.m_depth);
  708.   strcpybuff(OPTIONextdepth,maintab->m_option5.m_depth2);
  709.   
  710.   if(!maintab->m_option9.m_index) strcpybuff(OPTIONindex,"I0"); else OPTIONindex[0]='\0'; 
  711.   if(!maintab->m_option9.m_index2) strcpybuff(OPTIONindex2,"%I0"); else strcpybuff(OPTIONindex2,"%I"); 
  712.   if(maintab->m_option2.m_dos) strcpybuff(OPTIONdos,"L0"); else OPTIONdos[0]='\0'; 
  713.   if(maintab->m_option2.m_iso9660) strcpybuff(OPTIONdos,"L2"); else OPTIONdos[0]='\0'; 
  714.   if(maintab->m_option1.m_testall) strcpybuff(OPTIONtestall,"t"); else OPTIONtestall[0]='\0'; 
  715.   if(maintab->m_option1.m_parseall) strcpybuff(OPTIONparseall,"%P"); else strcpybuff(OPTIONparseall,"%P0"); 
  716.   if(maintab->m_option1.m_link) strcpybuff(OPTIONlink,"n"); else OPTIONlink[0]='\0'; 
  717.   if(maintab->m_option1.m_htmlfirst) strcpybuff(OPTIONhtmlfirst,"p7"); else strcpybuff(OPTIONhtmlfirst,""); 
  718.   if(maintab->m_option2.m_errpage) strcpybuff(OPTIONerrpage,"o0"); else OPTIONerrpage[0]='\0'; 
  719.   if(maintab->m_option2.m_external) strcpybuff(OPTIONexternal,"x"); else OPTIONexternal[0]='\0'; 
  720.   if(maintab->m_option2.m_nopurge) strcpybuff(OPTIONnopurge,"X0"); else OPTIONnopurge[0]='\0'; 
  721.   if(maintab->m_option2.m_hidepwd) strcpybuff(OPTIONhidepwd,"%x"); else OPTIONhidepwd[0]='\0'; 
  722.   if(maintab->m_option2.m_hidequery) strcpybuff(OPTIONhidequery,"%q0"); else OPTIONhidequery[0]='\0'; 
  723.   
  724.   OPTIONrobots[0]='\0';
  725.   if(maintab->m_option8.m_robots==0) strcpybuff(OPTIONrobots,"s0"); 
  726.   else if(maintab->m_option8.m_robots==1) strcpybuff(OPTIONrobots,"s1"); 
  727.   else if(maintab->m_option8.m_robots==2) strcpybuff(OPTIONrobots,"s2"); 
  728.   
  729.   // cookies,checktype,parsejava
  730.   if(maintab->m_option8.m_cookies==0) strcpybuff(OPTIONcookies,"b0"); // else strcpybuff(OPTIONcookies,"b1");
  731.   if (maintab->m_option8.m_checktype>=0)
  732.     sprintf(OPTIONchecktype,"u%d",maintab->m_option8.m_checktype);
  733.   if(maintab->m_option8.m_parsejava==0) strcpybuff(OPTIONparsejava,"j0"); // else strcpybuff(OPTIONcookies,"j1");
  734.   if (maintab->m_option8.m_http10) strcpybuff(OPTIONhttp10,"%h");   // HTTP/1.0 notamment
  735.   if (maintab->m_option8.m_toler)  strcpybuff(OPTIONtoler,"%B");    // tolerent
  736.   if (maintab->m_option8.m_updhack)  strcpybuff(OPTIONupdhack,"%s");    // update hack
  737.   
  738.   // store all in cache,logtype
  739.   if(maintab->m_option9.m_Cache2!=0) strcpybuff(OPTIONCache2,"k");
  740.   if(maintab->m_option9.m_logtype==1) strcpybuff(OPTIONlogtype,"z");
  741.   else if(maintab->m_option9.m_logtype==2) strcpybuff(OPTIONlogtype,"Z");
  742.   if (maintab->m_option3.m_windebug) strcatbuff(OPTIONlogtype,"%H");      // debug headers
  743.   
  744.   strcpybuff(build,"");
  745.   if      (maintab->m_option2.m_build==0) strcpybuff(build,"N0");
  746.   else if (maintab->m_option2.m_build==1) strcpybuff(build,"N1");
  747.   else if (maintab->m_option2.m_build==2) strcpybuff(build,"N2");
  748.   else if (maintab->m_option2.m_build==3) strcpybuff(build,"N3");
  749.   else if (maintab->m_option2.m_build==4) strcpybuff(build,"N4");
  750.   else if (maintab->m_option2.m_build==5) strcpybuff(build,"N5");
  751.   else if (maintab->m_option2.m_build==6) strcpybuff(build,"N100");
  752.   else if (maintab->m_option2.m_build==7) strcpybuff(build,"N101");
  753.   else if (maintab->m_option2.m_build==8) strcpybuff(build,"N102");
  754.   else if (maintab->m_option2.m_build==9) strcpybuff(build,"N103");
  755.   else if (maintab->m_option2.m_build==10) strcpybuff(build,"N104");
  756.   else if (maintab->m_option2.m_build==11) strcpybuff(build,"N105");
  757.   else if (maintab->m_option2.m_build==12) strcpybuff(build,"N99");
  758.   else if (maintab->m_option2.m_build==13) strcpybuff(build,"N199");
  759.   else if (maintab->m_option2.m_build==14) {
  760.     strcpybuff(build,"-N \"");
  761.     strcatbuff(build,maintab->m_option2.Bopt.m_BuildString);
  762.     strcatbuff(build,"\"");
  763.   }
  764.   
  765.   strcpybuff(filtre,"");
  766.   if      (maintab->m_option3.m_filter==0) strcpybuff(filtre,"p0");
  767.   else if (maintab->m_option3.m_filter==1) strcpybuff(filtre,"p1");
  768.   else if (maintab->m_option3.m_filter==2) strcpybuff(filtre,"p2");
  769.   else if (maintab->m_option3.m_filter==3) {    /* default */
  770.     if(!maintab->m_option1.m_htmlfirst) strcpybuff(filtre,"p3");
  771.   }
  772.   else if (maintab->m_option3.m_filter==4) strcpybuff(filtre,"p7");
  773.   //
  774.   if      (maintab->m_option3.m_travel==0) strcatbuff(filtre,"S");
  775.   else if (maintab->m_option3.m_travel==1) strcatbuff(filtre,"D");
  776.   else if (maintab->m_option3.m_travel==2) strcatbuff(filtre,"U");
  777.   else if (maintab->m_option3.m_travel==3) strcatbuff(filtre,"B");
  778.   //
  779.   if      (maintab->m_option3.m_travel2==0) strcatbuff(filtre,"a");
  780.   else if (maintab->m_option3.m_travel2==1) strcatbuff(filtre,"d");
  781.   else if (maintab->m_option3.m_travel2==2) strcatbuff(filtre,"l");
  782.   else if (maintab->m_option3.m_travel2==3) strcatbuff(filtre,"e");
  783.   //
  784.   if      (maintab->m_option3.m_travel3==0) strcatbuff(filtre,"K0");
  785.   else if (maintab->m_option3.m_travel3==1) strcatbuff(filtre,"K");
  786.   else if (maintab->m_option3.m_travel3==2) strcatbuff(filtre,"K3");
  787.   else if (maintab->m_option3.m_travel3==3) strcatbuff(filtre,"K4");
  788.  
  789.   if (maintab->m_option9.m_logf) strcpybuff(OPTIONlog,"f2"); else strcpybuff(OPTIONlog,"Q"); 
  790.   
  791.   if(maintab->m_option5.m_sizemax!=""){
  792.     strcpybuff(OPTIONmax,"M");
  793.     strcatbuff(OPTIONmax,maintab->m_option5.m_sizemax);
  794.   } else strcpybuff(OPTIONmax,"");
  795.   
  796.   if(maintab->m_option5.m_pausebytes!=""){
  797.     strcpybuff(OPTIONfrag,"G");
  798.     strcatbuff(OPTIONfrag,maintab->m_option5.m_pausebytes);
  799.   } else strcpybuff(OPTIONfrag,"");
  800.   
  801.   
  802.   if(maintab->m_option5.m_maxhtml!="" || maintab->m_option5.m_othermax!="" ){
  803.     strcpybuff(OPTIONmaxfile,"m");
  804.     if(maintab->m_option5.m_othermax!="") strcatbuff(OPTIONmaxfile,maintab->m_option5.m_othermax);
  805.     else strcatbuff(OPTIONmaxfile,"0");
  806.     if(maintab->m_option5.m_maxhtml!="") {strcatbuff(OPTIONmaxfile,",");strcatbuff(OPTIONmaxfile,maintab->m_option5.m_maxhtml);}
  807.     else {strcatbuff(OPTIONmaxfile,",");strcatbuff(OPTIONmaxfile,"0");}
  808.   } else strcpybuff(OPTIONmaxfile,"");
  809.   
  810.   if(strcmp(maintab->m_option4.m_connexion,"")!=0){
  811.     strcpybuff(OPTIONconn,"c");
  812.     strcatbuff(OPTIONconn,maintab->m_option4.m_connexion);
  813.   } else strcpybuff(OPTIONconn,"");
  814.   
  815.   if(strcmp(maintab->m_option4.m_timeout,"")!=0){
  816.     strcpybuff(OPTIONtime,"T");
  817.     strcatbuff(OPTIONtime,maintab->m_option4.m_timeout);
  818.   } else strcpybuff(OPTIONtime,"");
  819.   
  820.   // quitter host si timeout ou rate out
  821.   strcpybuff(OPTIONhostquit,"");
  822.   {
  823.     int a=0;
  824.     if (maintab->m_option4.m_remt)
  825.       a+=1;
  826.     if (maintab->m_option4.m_rems)
  827.       a+=2;
  828.     sprintf(OPTIONhostquit,"H%d",a);
  829.   }
  830.   
  831.   //--> max time
  832.   if(strcmp(maintab->m_option5.m_maxtime,"")!=0){
  833.     strcpybuff(OPTIONmaxtime,"E");
  834.     strcatbuff(OPTIONmaxtime,maintab->m_option5.m_maxtime);
  835.   } else strcpybuff(OPTIONmaxtime,"");
  836.   
  837.   //--> max rate
  838.   if(strcmp(maintab->m_option5.m_maxrate,"")!=0){
  839.     strcpybuff(OPTIONmaxrate,"A");
  840.     strcatbuff(OPTIONmaxrate,maintab->m_option5.m_maxrate);
  841.   } else strcpybuff(OPTIONmaxrate,"");
  842.   
  843.   if(strcmp(maintab->m_option5.m_maxconn,"")!=0){
  844.     strcpybuff(OPTIONmaxconn,"%c");
  845.     strcatbuff(OPTIONmaxconn,maintab->m_option5.m_maxconn);
  846.   } else strcpybuff(OPTIONmaxconn,"");
  847.   
  848.   if(strcmp(maintab->m_option5.m_maxlinks,"")!=0){
  849.     strcpybuff(OPTIONmaxlinks,"#L");
  850.     strcatbuff(OPTIONmaxlinks,maintab->m_option5.m_maxlinks);
  851.   } else strcpybuff(OPTIONmaxlinks,"");
  852.   
  853.   if(strcmp(maintab->m_option4.m_rate,"")!=0){
  854.     strcpybuff(OPTIONrate,"J");
  855.     strcatbuff(OPTIONrate,maintab->m_option4.m_rate);
  856.   } else strcpybuff(OPTIONrate,"");
  857.   
  858.   if(strcmp(maintab->m_option6.m_user,"")!=0){
  859.     strcpybuff(OPTIONuser,"\"");
  860.     strcatbuff(OPTIONuser,maintab->m_option6.m_user);
  861.     strcatbuff(OPTIONuser,"\"");
  862.   } else strcpybuff(OPTIONuser,"");
  863.   
  864.   if(strcmp(maintab->m_option6.m_footer,"")!=0){
  865.     strcpybuff(OPTIONfooter,"\"");
  866.     strcatbuff(OPTIONfooter,maintab->m_option6.m_footer);
  867.     strcatbuff(OPTIONfooter,"\"");
  868.   } else strcpybuff(OPTIONfooter,"");
  869.   
  870.   if(strcmp(maintab->m_option4.m_retry,"")!=0){
  871.     strcpybuff(OPTIONretry,"R");
  872.     strcatbuff(OPTIONretry,maintab->m_option4.m_retry);
  873.   } else strcpybuff(OPTIONretry,"");
  874.   
  875.   if(strcmp(maintab->m_option7.m_url2,"")!=0){
  876.     strcpybuff(buff_filtres,maintab->m_option7.m_url2);
  877.   } else strcpybuff(buff_filtres,"");
  878.   
  879.   
  880.   // MIME
  881.   buff_MIME[0]='\0';
  882.   ADD_MIME_IN_COPT(1)
  883.     ADD_MIME_IN_COPT(2)
  884.     ADD_MIME_IN_COPT(3)
  885.     ADD_MIME_IN_COPT(4)
  886.     ADD_MIME_IN_COPT(5)
  887.     ADD_MIME_IN_COPT(6)
  888.     ADD_MIME_IN_COPT(7)
  889.     ADD_MIME_IN_COPT(8)
  890.     
  891.     /* autres options: RAS */
  892.     if (dialog2->m_rasdisc)
  893.       disconnect=1;     /* dÈconnexion ‡ la fin */
  894.     else
  895.       disconnect=0;
  896. }
  897.  
  898. // Les routines ‡ dÈfinir:
  899. int __cdecl httrackengine_check(char* adr,char* fil,int status) {  // appelÈ par le wizard
  900.   return -1;
  901. }
  902. void __cdecl httrackengine_init() {    // appelÈ lors de l'init de HTTRACK, avant le dÈbut d'un miroir
  903. #if USE_RAS
  904.   has_started=0;
  905. #endif
  906.   httrackengine_loop(NULL,0,0,0,0,NULL,0);  // init
  907.   //printf("DEMARRAGE DU MIROIR DETECTE\n");  
  908. }
  909. void __cdecl httrackengine_uninit() {  // appelÈ en fin de miroir (peut Ítre utile!!!)
  910. #if USE_RAS
  911.   if (LibRasUse) {        /* librairie RAS chargÈe */
  912.     if (disconnect) {     /* on doit dÈconnecter */
  913.       if (connected) {    /* on a initiÈ une connexion */
  914.         if (conn)
  915.           LibRas->RasHangUp(conn);
  916.       } else {            /* tout dÈconnecter */
  917.         // On coupe tout (non, pas bourrin)
  918.         DWORD size;
  919.         RASCONN* adr;
  920.         int count=256;
  921.         size = sizeof(RASCONN)*(count+2);
  922.         adr = (RASCONN*) (char*) calloc(size,1);
  923.         if (adr) {
  924.           DWORD ent;
  925.           int i;
  926.           for(i=0;i<count;i++) {
  927.             adr[i].dwSize=sizeof(RASCONN);
  928.             strcpybuff(adr[i].szEntryName,"");
  929.           }
  930.           if (LibRas->RasEnumConnections((RASCONN*) adr,&size,&ent) == 0) {
  931.             for(i=0;i<(int)ent;i++) {
  932.               LibRas->RasHangUp(adr[i].hrasconn);
  933.             }
  934.           }
  935.           free(adr);
  936.         }
  937.         
  938.       }
  939.     }
  940.   }
  941. #endif
  942. }
  943. int __cdecl httrackengine_start(void* dummy) {   // appelÈ lors du dÈmarrage du miroir (premiËres requËtes)
  944. #if USE_RAS
  945.   // connexion RAS
  946.   has_started=1;    // dÈmarrage
  947.   connected=0;
  948.   conn = NULL;
  949.   memset(&SInfo, 0, sizeof(SInfo));
  950.   if (LibRasUse) {
  951.     if (strlen(OPTION_RasString)>0) {    // sÈlection provider
  952.       if (!LibRas->RasDial(NULL,NULL,&OPTION_dial,NULL,NULL,&conn)) {
  953.         RASCONNSTATUS status;
  954.         do {
  955.           status.dwSize = sizeof(status);
  956.           LibRas->RasGetConnectStatus(conn,&status);
  957.           switch(status.rasconnstate) {
  958.           case RASCS_Connected : 
  959.             connected=1;
  960.             break;
  961.           case RASCS_Disconnected :
  962.             strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider"*/));
  963.             connected=-1;
  964.             break;
  965.           }
  966.         } while(connected==0);
  967.       } else {
  968.         strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider","Impossible d'Ètablir la connexion"*/));
  969.         connected=-1;
  970.         //termine=1;
  971.       }
  972.     }
  973.     //
  974.     if (connected != -1)  // si pas d'erreur RAS
  975.       return 1;
  976.     else
  977.       return 0;
  978.   } else
  979.     return 1;
  980. #else
  981.   return 1;
  982. #endif
  983. }
  984. int  httrackengine_end() {     // appelÈ lors de la fin du miroir (plus de liens ‡ charger)
  985.   WHTT_LOCK();
  986.   termine=1;
  987.   if (_Cinprogress_inst) {
  988.     _Cinprogress_inst->EndDialog(IDOK);
  989.     _Cinprogress_inst=NULL;
  990.   }
  991.   WHTT_UNLOCK();
  992.   return 1;
  993. }
  994. int __cdecl httrackengine_htmlcheck(char* html,int len,char* url_adresse,char* url_fichier) {    // appelÈ ‡ chaque fois qu'un html doit Ítre scannÈ (utile pour la prospection mais inutile ici)
  995.   return 1;
  996. }
  997. int __cdecl httrackengine_chopt(void* opt) {
  998.   return 1;
  999. }
  1000.  
  1001. // Le routine la plus utile sans doute: elle refresh les tableaux
  1002. // C'est la 2e routine en thread qui assure le refresh graphique
  1003. // (plus efficace)
  1004. // -->C'est elle qui dÈcide de tout arrÍter si elle dÈtecte in termine_request<--
  1005. int __cdecl httrackengine_loop(
  1006.                                void* _back,int back_max,int back_index,
  1007.                                int lien_n,int lien_tot,
  1008.                                int stat_time,
  1009.                                hts_stat_struct* stats) {    // appelÈ ‡ chaque boucle de HTTrack
  1010.   static char s[HTS_URLMAXSIZE*2]="";  // utilisÈ plus loin
  1011.   int stat_written=-1;
  1012.   int stat_updated=-1;
  1013.   int stat_errors=-1;
  1014.   int stat_warnings=-1;
  1015.   int stat_infos=-1;
  1016.   int nbk=-1;
  1017.   LLint nb=-1;
  1018.   int stat_nsocket=-1;
  1019.   LLint stat_bytes=-1;
  1020.   LLint stat_bytes_recv=-1;
  1021.   int irate=-1;
  1022.   
  1023.   WHTT_LOCK();
  1024.  
  1025.   if (stats) {
  1026.     stat_written=stats->stat_files;
  1027.     stat_updated=stats->stat_updated_files;
  1028.     stat_errors=stats->stat_errors;
  1029.     stat_warnings=stats->stat_warnings;
  1030.     stat_infos=stats->stat_infos;
  1031.     nbk=stats->nbk;
  1032.     stat_nsocket=stats->stat_nsocket;
  1033.     irate=(int)stats->rate;
  1034.     nb=stats->nb;
  1035.     stat_bytes=stats->nb;
  1036.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  1037.   }
  1038.   
  1039. #if !SHELL_MULTITHREAD
  1040.   static TStamp last_time;
  1041. #endif
  1042.   int rate;
  1043.   // casts
  1044.   lien_back* back=(lien_back*) _back;
  1045.   //  static int ft=-1;
  1046.   
  1047.   if (back_max == 0) {
  1048. #if !SHELL_MULTITHREAD
  1049.     last_time=0;
  1050. #endif
  1051.     // en cas de manque de time
  1052.     SInfo.stat_timestart=time_local();
  1053.     WHTT_UNLOCK();
  1054.     return 1;
  1055.   }
  1056.   
  1057.   if ((termine) || (termine_requested)) {
  1058.     SInfo.refresh=0;      // pas de refresh
  1059.     SInfo.refresh=0;      // pas de refresh
  1060.     termine_requested=1;
  1061.     WHTT_UNLOCK();
  1062.     return 0;
  1063.   }
  1064.   
  1065.   if (stat_written>=0) SInfo.stat_written=stat_written;
  1066.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  1067.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  1068.   if (stat_warnings>=0)  SInfo.stat_warnings=stat_warnings;
  1069.   if (stat_infos>=0)  SInfo.stat_infos=stat_infos;
  1070.   
  1071. #if SHELL_MULTITHREAD 
  1072.   //if (((tl-last_time)>=100) || ((tl-last_time)<0)) {   // chaque 100 ms
  1073.   if (SInfo.ask_refresh) {
  1074. #else
  1075.     TStamp tl=0;
  1076.     {
  1077.       time_t tt;
  1078.       struct tm* A;
  1079.       tt=time(NULL);
  1080.       A=localtime(&tt);
  1081.       tl+=A->tm_sec;
  1082.       tl+=A->tm_min*60;
  1083.       tl+=A->tm_hour*60*60;
  1084.       //tl+=A->tm_yday*60*60*24;
  1085.       //tl+=A->tm_year*60*60*24*365;
  1086.       
  1087.       tl*=1000;  // en ms
  1088.       
  1089.       struct _timeb timebuffer;
  1090.       char *timeline;
  1091.       _ftime( &timebuffer );
  1092.       timeline = ctime( & ( timebuffer.time ) );
  1093.       
  1094.       tl+=timebuffer.millitm;    // + ms
  1095.     }
  1096.     if (((tl-last_time)>=HTS_SLEEP_WIN) || ((tl-last_time)<0)) {   // chaque 250 ms
  1097.       last_time=tl;
  1098. #endif
  1099.       //INFILLMEM_LOCKED=1;    // locker interface
  1100.       // OPTI int rate;
  1101.       SInfo.ask_refresh=0;
  1102.       
  1103.       // pour Èviter temps cpu consommÈ trop grand
  1104.       // Sleep(10);
  1105.       
  1106.       // initialiser ft
  1107.       if ((stat_nsocket==-1)) {
  1108.         if (SInfo.ft==-1) {
  1109.           SInfo.ft=stat_time;
  1110.         }
  1111.       }
  1112.       
  1113. #if !SHELL_MULTITHREAD
  1114.       //
  1115.       MSG msg;  
  1116.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )) {     
  1117.         switch (msg.message) {
  1118.         case WM_COMMAND:        
  1119.           switch(msg.wParam) { 
  1120.           case ID_APP_ABOUT: {
  1121.             Cabout about;
  1122.             about.DoModal();                                    }
  1123.             break;
  1124.           case ID_APP_EXIT: case WM_CLOSE :
  1125.             termine_requested=1;
  1126.             break;
  1127.           case  WM_DESTROY: case WM_NCDESTROY: 
  1128.             termine_requested=1;
  1129.             break;
  1130.           }
  1131.           break;        
  1132.           default:
  1133.             DefWindowProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
  1134.             break;
  1135.         }
  1136.       }
  1137.       //
  1138. #endif
  1139.       
  1140.       // calculer heure si ce n'est dÈja fait
  1141.       if (stat_time<0)
  1142.         SInfo.stat_time=(int) (time_local()-SInfo.stat_timestart);
  1143.       
  1144.       // calculer transfer rate
  1145.       if ((stat_time>0) && (stat_bytes_recv>0))
  1146.         rate=(int)(stat_bytes_recv/stat_time);
  1147.       else
  1148.         rate=0;    // pas d'infos
  1149.       
  1150.       // stocker infos: octets transfÈrÈs, temps, etc.
  1151.       if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  1152.       if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  1153.       if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  1154.       if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  1155.       SInfo.stat_nsocket=stat_nsocket;          // socks
  1156.       if (rate>0)  SInfo.rate=rate;                // rate
  1157.       if (irate>=0) SInfo.irate=irate;             // irate
  1158.       if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  1159.       if (SInfo.stat_back>=0) SInfo.stat_back=nbk;
  1160.       
  1161.       // back: tableau de back_max ÈlÈments de cache
  1162.       // back_max: nombre d'ÈlÈments ^^^^
  1163.       // lien_tot: nombre total de liens traitÈs pour le moment
  1164.       // stat_bytes: octets sauvegardÈs
  1165.       // stat_bytes_recv: octets tÈlÈchargÈs
  1166.       // stat_time: temps en seconde depuis le dÈbut du miroir
  1167.       // stat_nsocket: nombre de sockets connectÈes actuellement
  1168.       // on peut en dÈduire rate=stat_bytes_recv/stat_time
  1169.       
  1170.       // printf("loop.. %d liens, %d octets, %d secondes, %d sockets, TAUX=%d\n",lien_tot,stat_bytes,stat_time,stat_nsocket,rate);
  1171.       
  1172.       // parcourir registre des liens
  1173.       if (back_index>=0) {  // seulement si index passÈ
  1174.         int j,k;
  1175.         int index=0;
  1176.         int ok=0;         // idem
  1177.         int l;            // idem
  1178.         int M=32;         // idem
  1179.         
  1180.         StatsBufferback=(void*) back;
  1181.         StatsBufferback_max=back_max;
  1182.         {
  1183.           int i;
  1184.           for(i=0;i<NStatsBuffer;i++) {
  1185.             strcpybuff(StatsBuffer[i].etat,"");
  1186.             strcpybuff(StatsBuffer[i].nom,"");
  1187.             strcpybuff(StatsBuffer[i].fichier,"");
  1188.             strcpybuff(StatsBuffer[i].url_sav,"");
  1189.             StatsBuffer[i].back=NULL;
  1190.             StatsBuffer[i].size=0;
  1191.             StatsBuffer[i].sizetot=0;
  1192.           }
  1193.         }
  1194.         for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  1195.           for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritÈ
  1196.             int _i;
  1197.             for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  1198.               int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  1199.               if (back[i].status>=0) {     // signifie "lien actif"
  1200.                 // int ok=0;  // OPTI
  1201.                 ok=0;
  1202.                 switch(j) {
  1203.                 case 0:     // prioritaire
  1204.                   if ((back[i].status>0) && (back[i].status<99)) {
  1205.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F4 /*"receive","rÈception"*/)); ok=1;
  1206.                   }
  1207.                   break;
  1208.                 case 1:
  1209.                   if (back[i].status==99) {
  1210.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F5 /*"request","requËte"*/)); ok=1;
  1211.                   }
  1212.                   else if (back[i].status==100) {
  1213.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1214.                   }
  1215.                   else if (back[i].status==101) {
  1216.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F7 /*"search","recherche"*/)); ok=1;
  1217.                   }
  1218.                   else if (back[i].status==1000) {    // ohh le beau ftp
  1219.                     sprintf(StatsBuffer[index].etat,"ftp: %s",back[i].info); ok=1;
  1220.                   }
  1221.                   else if (back[i].status==102) {         // SSL handshake
  1222.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1223.                   }
  1224.                   break;
  1225.                 default:
  1226.                   if (back[i].status==0) {  // prÍt
  1227.                     if ((back[i].r.statuscode==200)) {
  1228.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8 /*"ready","prÍt"*/)); ok=1;
  1229.                     }
  1230.                     else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  1231.                       char tempo[256]; tempo[0]='\0';
  1232.                       infostatuscode(tempo,back[i].r.statuscode);
  1233.                       strcpybuff(StatsBuffer[index].etat,tempo); ok=1;
  1234.                     }
  1235.                     else {
  1236.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F9 /*"error","erreur"*/)); ok=1;
  1237.                     }
  1238.                   }
  1239.                   break;
  1240.                 }
  1241.                 
  1242.                 if (ok) {
  1243.                   // OPTI int l;
  1244.                   // OPTI int M=32;     // longueur
  1245.                   // OPTI char s[HTS_URLMAXSIZE*2]="";
  1246.                   //
  1247.                   StatsBuffer[index].back=i;        // index pour + d'infos
  1248.                   //
  1249.                   s[0]='\0';
  1250.                   strcpybuff(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  1251.                   if (strcmp(back[i].url_adr,"file://"))
  1252.                     strcatbuff(s,back[i].url_adr);
  1253.                   else
  1254.                     strcatbuff(s,"localhost");
  1255.                   if (back[i].url_fil[0]!='/')
  1256.                     strcatbuff(s,"/");
  1257.                   strcatbuff(s,back[i].url_fil);
  1258.                   
  1259.                   StatsBuffer[index].fichier[0]='\0';
  1260.                   {
  1261.                     char* a=strrchr(s,'/');
  1262.                     if (a) {
  1263.                       strncatbuff(StatsBuffer[index].fichier,a,200);
  1264.                       *a='\0';
  1265.                     }
  1266.                   }
  1267.                   
  1268.                   if ((l=strlen(s))<MAX_LEN_INPROGRESS)
  1269.                     strcpybuff(StatsBuffer[index].nom,s);
  1270.                   else {
  1271.                     // couper
  1272.                     StatsBuffer[index].nom[0]='\0';
  1273.                     strncatbuff(StatsBuffer[index].nom,s,MAX_LEN_INPROGRESS/2-2);
  1274.                     strcatbuff(StatsBuffer[index].nom,"...");
  1275.                     strcatbuff(StatsBuffer[index].nom,s+l-MAX_LEN_INPROGRESS/2+2);
  1276.                   }
  1277.                   
  1278.                   //if (back[i].url_fil[0]!='/') printf("/");
  1279.                   
  1280.                   if (back[i].r.totalsize>0) {  // taille prÈdÈfinie
  1281.                     StatsBuffer[index].sizetot=back[i].r.totalsize;
  1282.                     StatsBuffer[index].size=back[i].r.size;
  1283.                   } else {  // pas de taille prÈdÈfinie
  1284.                     if (back[i].status==0) {  // prÍt
  1285.                       StatsBuffer[index].sizetot=back[i].r.size;
  1286.                       StatsBuffer[index].size=back[i].r.size;
  1287.                     } else {
  1288.                       StatsBuffer[index].sizetot=8192;
  1289.                       StatsBuffer[index].size=(back[i].r.size % 8192);
  1290.                     }
  1291.                   }
  1292.                   index++;
  1293.                 }
  1294.               }
  1295.             }
  1296.           }
  1297.         }
  1298.     }
  1299.     
  1300. #if SHELL_MULTITHREAD
  1301.     SInfo.refresh=1;     // on signale qu'il faut faire un refresh!
  1302. #else
  1303.     inprogress_refresh();  // tout de suite (non multithread)
  1304. #endif
  1305.     // INFILLMEM_LOCKED=0;    // dÈlocker interface
  1306.   }
  1307.   WHTT_UNLOCK();
  1308.   return (termine==0);
  1309. }
  1310.  
  1311. int inprogress_refresh() {
  1312.   static int toggle=0;
  1313.   // WHTT_LOCK(); // deja fait
  1314.   if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1315.     if (SInfo.refresh) {
  1316.       // INREDRAW_LOCKED=1;
  1317.       // REFRESH (si nb de socket==-1 on manage les fenetres)
  1318.       int icn;
  1319.       icn=inprogress->IsIconic();
  1320.       CString lnk;
  1321.       if (SInfo.stat_back)
  1322.         lnk.Format("%d/%d (+%d)",SInfo.lien_n,SInfo.lien_tot-1,SInfo.stat_back);
  1323.       else
  1324.         lnk.Format("%d/%d",SInfo.lien_n,SInfo.lien_tot-1);
  1325.       if (!icn) {
  1326.         int parsing=0;
  1327.         if (!soft_term_requested) {
  1328.           if (!hts_setpause(-1)) {
  1329.             if (!(parsing=hts_is_parsing(-1)))
  1330.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F10 /*"Receiving files.","RÈception des fichiers"*/)); 
  1331.             else {
  1332.               switch(hts_is_testing()) {
  1333.               case 0:
  1334.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11 /*"Parsing HTML file..","Parcours du fichier HTML"*/)); 
  1335.                 break;
  1336.               case 1:
  1337.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F12 /*"Parsing HTML file (testing links)..","Parcours du fichier HTML (test des liens)"*/)); 
  1338.                 break;
  1339.               case 2:
  1340.                 inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F11b)); 
  1341.                 break;
  1342.               }
  1343.             }
  1344.           } else {
  1345.             if (((toggle++)/5)%2)
  1346.               inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13 /*"Paused (select [File]/[Pause transfer] to continue)","Interrompu (choisir [Fichier]/[Interrompre transferts] pour continuer)"*/));
  1347.             else
  1348.               inprogress->SetDlgItemText(IDC_inforun,"");
  1349.           }
  1350.         } else {
  1351.           if (((toggle++)/5)%2)
  1352.             inprogress->SetDlgItemText(IDC_inforun,LANG(LANG_F13b));
  1353.           else
  1354.             inprogress->SetDlgItemText(IDC_inforun,"");
  1355.         }
  1356.         
  1357.         if (SInfo.stat_time>0) {
  1358.           char s[256];
  1359.           qsec2str(s,(TStamp) SInfo.stat_time);
  1360.           inprogress->SetDlgItemText(IDC_i1 ,s);  // time
  1361.         } else
  1362.           inprogress->SetDlgItemText(IDC_i1 , _SN(SInfo.stat_time) );  // time
  1363.         inprogress->SetDlgItemText(IDC_i0 , int2bytes(SInfo.stat_bytes) );  // bytes
  1364.         inprogress->SetDlgItemText(IDC_i2 , lnk);  // scanned
  1365.         if (SInfo.stat_nsocket>0)
  1366.           inprogress->SetDlgItemText(IDC_i3 , _SN(SInfo.stat_nsocket) );  // socks
  1367.         else
  1368.           inprogress->SetDlgItemText(IDC_i3 , "none" );  // wait
  1369.         
  1370.         CString st;
  1371.         st.Format("%s (%s)",int2bytessec(SInfo.irate),int2bytessec(SInfo.rate));
  1372.         inprogress->SetDlgItemText(IDC_i4 , st );  // rate
  1373.         
  1374.         inprogress->SetDlgItemText(IDC_i5 , _SN(SInfo.stat_errors) );
  1375.         inprogress->SetDlgItemText(IDC_i6 , _SN(SInfo.stat_written) );
  1376.         {
  1377.           char tempo[256];
  1378.           int pc=0;
  1379.           if (SInfo.stat_written)
  1380.             pc=(int)((SInfo.stat_updated*100)/(SInfo.stat_written));
  1381.           if (pc)
  1382.             sprintf(tempo,"%d (%d%%)",SInfo.stat_updated,pc);
  1383.           else
  1384.             sprintf(tempo,"%d",SInfo.stat_updated);
  1385.           inprogress->SetDlgItemText(IDC_i7 , tempo );
  1386.         }
  1387.         
  1388.         /*if (!parsing)*/
  1389.         {
  1390.           {
  1391.             int i;
  1392.             for(i=0;i<NStatsBuffer;i++) {
  1393.               if (StatsBuffer[i].sizetot>0) {
  1394.                 TStamp d = ((TStamp) StatsBuffer[i].size * 1000);
  1395.                 d = d / ((TStamp) StatsBuffer[i].sizetot);
  1396.                 StatsBuffer[i].offset = (int) d;
  1397.               } else
  1398.                 StatsBuffer[i].offset = 0;
  1399.             }
  1400.           }
  1401.           
  1402.           if (!parsing)
  1403.             inprogress->m_sl0.SetRange(0,1000);
  1404.           inprogress->m_sl1.SetRange(0,1000);
  1405.           inprogress->m_sl2.SetRange(0,1000);
  1406.           inprogress->m_sl3.SetRange(0,1000);
  1407.           inprogress->m_sl4.SetRange(0,1000);
  1408.           inprogress->m_sl5.SetRange(0,1000);
  1409.           inprogress->m_sl6.SetRange(0,1000);
  1410.           inprogress->m_sl7.SetRange(0,1000);
  1411.           inprogress->m_sl8.SetRange(0,1000);
  1412.           inprogress->m_sl9.SetRange(0,1000);
  1413.           inprogress->m_sl10.SetRange(0,1000);
  1414.           inprogress->m_sl11.SetRange(0,1000);
  1415.           inprogress->m_sl12.SetRange(0,1000);
  1416.           inprogress->m_sl13.SetRange(0,1000);
  1417.           
  1418.           if (!parsing)
  1419.             inprogress->m_sl0.SetPos(StatsBuffer[0].offset);
  1420.           inprogress->m_sl1.SetPos(StatsBuffer[1].offset);
  1421.           inprogress->m_sl2.SetPos(StatsBuffer[2].offset);
  1422.           inprogress->m_sl3.SetPos(StatsBuffer[3].offset);
  1423.           inprogress->m_sl4.SetPos(StatsBuffer[4].offset);
  1424.           inprogress->m_sl5.SetPos(StatsBuffer[5].offset);
  1425.           inprogress->m_sl6.SetPos(StatsBuffer[6].offset);
  1426.           inprogress->m_sl7.SetPos(StatsBuffer[7].offset);
  1427.           inprogress->m_sl8.SetPos(StatsBuffer[8].offset);
  1428.           inprogress->m_sl9.SetPos(StatsBuffer[9].offset);
  1429.           inprogress->m_sl10.SetPos(StatsBuffer[10].offset);
  1430.           inprogress->m_sl11.SetPos(StatsBuffer[11].offset);
  1431.           inprogress->m_sl12.SetPos(StatsBuffer[12].offset);
  1432.           inprogress->m_sl13.SetPos(StatsBuffer[13].offset);
  1433.           
  1434.           // redraw en boucle
  1435.           {
  1436.             int i=0;
  1437.             if (parsing)
  1438.               i++;
  1439.             for( ; i<NStatsBuffer;i++) {
  1440.               inprogress->element[0][i]->SetWindowText(StatsBuffer[i].etat);
  1441.               inprogress->element[1][i]->SetWindowText(StatsBuffer[i].nom);
  1442.               inprogress->element[4][i]->SetWindowText(StatsBuffer[i].fichier);
  1443.               
  1444.               if ((strlen(StatsBuffer[i].etat)==0) != StatsBuffer[i].actived) {
  1445.                 StatsBuffer[i].actived=!StatsBuffer[i].actived;
  1446.                 if (!StatsBuffer[i].actived)
  1447.                   inprogress->element[3][i]->ModifyStyle(WS_DISABLED,0);
  1448.                 else
  1449.                   inprogress->element[3][i]->ModifyStyle(0,WS_DISABLED);
  1450.                 inprogress->element[3][i]->RedrawWindow();
  1451.               }
  1452.             }
  1453.           }
  1454.           //
  1455.         }
  1456.         /* else*/
  1457.         if (parsing) {  // parsing
  1458.           //
  1459.           inprogress->m_sl0.SetRange(0,100);
  1460.           inprogress->m_sl0.SetPos(parsing);
  1461.           inprogress->element[0][0]->SetWindowText(LANG(LANG_F14 /*"scanning","parcours"*/));
  1462.           inprogress->element[1][0]->SetWindowText(StatsBuffer[0].nom);
  1463.           inprogress->element[4][0]->SetWindowText("");
  1464.           //inprogress->element[0][1]->SetWindowText();
  1465.         }
  1466.         
  1467.       }
  1468.       {
  1469.         static char last_info[256]="";
  1470.         char info[256];
  1471.         if ((SInfo.stat_nsocket==-1)) {
  1472. #if USE_RAS
  1473.           if (!has_started)
  1474. #endif
  1475.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F15 /*"Waiting for specific hour to start","Attente de l'heure programmÈe pour dÈmarrer"*/));
  1476. #if USE_RAS
  1477.           else
  1478.             inprogress->SetDlgItemText(IDC_nm0,LANG(LANG_F16 /*"Connecting to provider","Connexion au provider"*/));
  1479. #endif
  1480.           inprogress->m_sl0.SetRange(0,SInfo.ft);
  1481.           inprogress->m_sl0.SetPos(SInfo.ft-SInfo.stat_time);  // temps restant
  1482.           // inprogress->SetDlgItemText(IDC_nm1,_SN(ft));
  1483.           if (icn && (!this_CSplitterFrame->iconifie)) {  // minimisÈe mais pas en icone
  1484.             sprintf(info,"[%d s]",SInfo.stat_time);
  1485.           } else {
  1486.             sprintf(info,LANG(LANG_F17 /*"Mirror waiting [%d seconds]","Miroir en attente [%d secondes]"*/),SInfo.stat_time);
  1487.           }
  1488.         } else {
  1489.           if (icn) {  // minimisÈe
  1490.             sprintf(info,"[%s]",lnk);
  1491.           } else {
  1492.             sprintf(info,LANG(LANG_F18 /*"Mirror in progress [%s, %d bytes]","Miroir en cours [%s, %d octets]"*/),lnk,SInfo.stat_bytes);
  1493.           }
  1494.         }
  1495.         if (strcmp(info,last_info)) {       /* a changÈ */
  1496.           strcpybuff(last_info,info);           /* recopier */
  1497.           if (this_CSplitterFrame->iconifie)  // minimisÈ icone
  1498.             this_CSplitterFrame->IconChange(last_info);
  1499.           else
  1500.             this_app->GetMainWnd()->SetWindowText(last_info);
  1501.         }
  1502.       }  
  1503.       
  1504.       //inprogress->UpdateWindow();
  1505.     } else {
  1506.     }
  1507.   }
  1508.   // WHTT_UNLOCK();
  1509.   return 1;
  1510. }
  1511.  
  1512. /*
  1513. // refresh scan
  1514. int inprogress_refresh_scan() {
  1515. if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1516. if (!SInfo.refresh) {
  1517. if (!inprogress->IsIconic()) {
  1518. int n;
  1519. // patch pour le scanning
  1520. if (n=hts_is_parsing()) {
  1521. strcpybuff(StatsBuffer[0].etat,"scanning");
  1522. inprogress->element[0][0]->SetWindowText("scanning");
  1523. StatsBuffer[0].sizetot=100;
  1524. StatsBuffer[0].size=n;
  1525. inprogress->m_sl0.SetRange(0,100);  // progression en % du scanning
  1526. inprogress->m_sl0.SetPos(n);
  1527. //} else {
  1528. //  inprogress->element[0][0]->SetWindowText("...");
  1529. }
  1530. }
  1531. }
  1532. }
  1533. return 1;
  1534. }
  1535. */
  1536.  
  1537. /* Plantages si DoModal() dans un thread != du principal.. passons.. */
  1538. char* __cdecl httrackengine_query(char* question) {
  1539.   strcpybuff(WIZ_question,question);
  1540.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest1,0);
  1541.   return WIZ_reponse;
  1542. }
  1543.  
  1544. char* __cdecl httrackengine_query2(char* question) {
  1545.   strcpybuff(WIZ_question,question);
  1546.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest2,0);
  1547.   return WIZ_reponse;
  1548. }
  1549.  
  1550. char* __cdecl httrackengine_query3(char* question) {
  1551.   strcpybuff(WIZ_question,question);
  1552.   AfxGetMainWnd()->SendMessage(WM_COMMAND,wm_WizRequest3,0);
  1553.   return WIZ_reponse;
  1554. }
  1555.  
  1556. void __cdecl httrackengine_pause(char* lockfile) {
  1557.   AfxMessageBox("Engine paused.. click OK to continue!",MB_OK);
  1558.   remove(lockfile);
  1559. }
  1560.  
  1561. // modif RX 10/10/98 pour gestion des , et des tabs
  1562. char* connversion(char* chaine)
  1563. {
  1564.   for(int i=0;i < (int) strlen(chaine);i++) 
  1565.     if(chaine[i]=='\n') chaine[i]=' ';
  1566.     else if(chaine[i]==13) chaine[i]=' ';
  1567.     else if(chaine[i]==9) chaine[i]=' ';
  1568.     /*else if(chaine[i]==',') chaine[i]=' ';*/
  1569.     
  1570.     return chaine;
  1571. }
  1572.  
  1573.  
  1574. #if SHELL_MULTITHREAD
  1575. void __cdecl RunBackRobot(void* al_p) {
  1576.   int argc;
  1577.   char** argv;
  1578.   
  1579.   while((!inprogress) && (!termine)) Sleep(10);
  1580.   if (inprogress)
  1581.     while ((!inprogress->m_hWnd) || (termine)) Sleep(10);   // attendre formulaire
  1582.     //Sleep(100);
  1583.     
  1584.     Robot_params* al=(Robot_params*) al_p;
  1585.     argc = al->argc;
  1586.     argv = al->argv;
  1587.     /* launch the engine */
  1588.     hts_init();
  1589.     HTTRACK_result=hts_main(argc,argv);
  1590.     /* clear all vars */
  1591.     WHTT_LOCK();
  1592.     termine=1;
  1593.     WHTT_UNLOCK();
  1594.     hts_uninit();
  1595.     
  1596.     _endthread();
  1597. }
  1598. #endif
  1599.  
  1600. // modifs RX 10/10/98: gestion des ,
  1601. CString change(char* chaine,char c) {
  1602.   int comma=1; int first=1;
  1603.   CString chaine1;
  1604.   for(int i=0;i < (int) strlen(chaine);i++) {
  1605.     switch(chaine[i]) {
  1606.     case 10: case 13: case 9: case ' ': case ',':
  1607.       comma=1; 
  1608.       break;
  1609.     default:
  1610.       if (comma) {
  1611.         if (!first) chaine1 +=' ';
  1612.         else first=0; 
  1613.         chaine1  +=c; 
  1614.         comma=0;
  1615.       }
  1616.       chaine1 += chaine[i]; 
  1617.       break;
  1618.     }
  1619.   }
  1620.   return chaine1;
  1621. }
  1622.  
  1623.  
  1624. // Lancement
  1625. void lance(void) {
  1626.   char *argv[1999];
  1627.   int argc=1;
  1628.   int g=0;
  1629.   int i =0;
  1630.   
  1631.   //
  1632.   if (fp_debug) {
  1633.     fprintf(fp_debug,"Building command line\r\n");
  1634.     fflush(fp_debug);
  1635.   }
  1636.   //
  1637.   LINE[0]='\0';
  1638.   strcpybuff(LINE,"-");
  1639.   if (choixdeb[0]!='W')
  1640.     strcatbuff(LINE,"q");         // quiet
  1641.   
  1642.   if (choixdeb[0]=='/')
  1643.     strcatbuff(LINE,"i");
  1644.   else if (choixdeb[0]!='!')
  1645.     strcatbuff(LINE,choixdeb);
  1646.   // option de profondeur
  1647.   if(strcmp(OPTIONdepth,"")!=0) { 
  1648.     strcatbuff(LINE,"r");
  1649.     strcatbuff(LINE,OPTIONdepth);
  1650.   }
  1651.   if(strcmp(OPTIONextdepth,"")!=0) { 
  1652.     strcatbuff(LINE,"%e");
  1653.     strcatbuff(LINE,OPTIONextdepth);
  1654.   }
  1655.   if(strcmp(OPTIONcache,"")!=0) strcatbuff(LINE,OPTIONcache);
  1656.   if(strcmp(OPTIONnorecatch,"")!=0) strcatbuff(LINE,OPTIONnorecatch);
  1657.   if(strcmp(OPTIONtestall,"")!=0) strcatbuff(LINE,OPTIONtestall);
  1658.   if(strcmp(OPTIONparseall,"")!=0) strcatbuff(LINE,OPTIONparseall);
  1659.   if(strcmp(OPTIONlink,"")!=0) strcatbuff(LINE,OPTIONlink);
  1660.   if(strcmp(OPTIONexternal,"")!=0) strcatbuff(LINE,OPTIONexternal);
  1661.   if(strcmp(OPTIONnopurge,"")!=0) strcatbuff(LINE,OPTIONnopurge);
  1662.   if(strcmp(OPTIONhidepwd,"")!=0) strcatbuff(LINE,OPTIONhidepwd);
  1663.   if(strcmp(OPTIONhidequery,"")!=0) strcatbuff(LINE,OPTIONhidequery);
  1664.   if(strcmp(OPTIONrobots,"")!=0) strcatbuff(LINE,OPTIONrobots);
  1665.   if(strcmp(OPTIONcookies,"")!=0) strcatbuff(LINE,OPTIONcookies);
  1666.   if(strcmp(OPTIONchecktype,"")!=0) strcatbuff(LINE,OPTIONchecktype);
  1667.   if(strcmp(OPTIONparsejava,"")!=0) strcatbuff(LINE,OPTIONparsejava);
  1668.   if(strcmp(OPTIONCache2,"")!=0) strcatbuff(LINE,OPTIONCache2);
  1669.   if(strcmp(OPTIONlogtype,"")!=0) strcatbuff(LINE,OPTIONlogtype);
  1670.   if (strlen(OPTIONhttp10)) strcatbuff(LINE,OPTIONhttp10);
  1671.   if (strlen(OPTIONtoler)) strcatbuff(LINE,OPTIONtoler);
  1672.   if (strlen(OPTIONupdhack)) strcatbuff(LINE,OPTIONupdhack);
  1673.   
  1674.   // si get, ne pas faire
  1675.   if (strcmp(choixdeb,"g")!=0) {
  1676.     if(build[0]=='-') {
  1677.       strcatbuff(LINE," ");
  1678.       strcatbuff(LINE,build);
  1679.       strcatbuff(LINE," -");
  1680.     } else if (strcmp(build,"")!=0) strcatbuff(LINE,build);
  1681.   }
  1682.   strcatbuff(LINE,OPTIONdos);
  1683.   strcatbuff(LINE,OPTIONindex);
  1684.   strcatbuff(LINE,OPTIONindex2);
  1685.   strcatbuff(LINE,OPTIONhtmlfirst);
  1686.   strcatbuff(LINE,filtre);
  1687.   strcatbuff(LINE,OPTIONmax);
  1688.   strcatbuff(LINE,OPTIONfrag);
  1689.   strcatbuff(LINE,OPTIONmaxfile);
  1690.   strcatbuff(LINE,OPTIONconn);
  1691.   strcatbuff(LINE,OPTIONtime);
  1692.   strcatbuff(LINE,OPTIONrate);
  1693.   strcatbuff(LINE,OPTIONretry);
  1694.   strcatbuff(LINE,OPTIONhostquit);
  1695.   strcatbuff(LINE,OPTIONlog);
  1696.   strcatbuff(LINE,OPTIONerrpage);
  1697.   //-->
  1698.   strcatbuff(LINE,OPTIONwaittime);
  1699.   strcatbuff(LINE,OPTIONmaxtime);
  1700.   strcatbuff(LINE,OPTIONmaxrate);
  1701.   strcatbuff(LINE,OPTIONmaxconn);
  1702.   strcatbuff(LINE,OPTIONmaxlinks);
  1703.   strcatbuff(LINE,"#f");  // flush
  1704.   
  1705.   if (strcmp(OPTIONuser,"")!=0) {strcatbuff(LINE," ");strcatbuff(LINE,"-F");strcatbuff(LINE," ");strcatbuff(LINE,OPTIONuser);}
  1706.   if (strcmp(OPTIONfooter,"")!=0) {strcatbuff(LINE," ");strcatbuff(LINE,"-%F");strcatbuff(LINE," ");strcatbuff(LINE,OPTIONfooter);}
  1707.   
  1708.   if ((int)strlen(OPTIONproxy)>0) {
  1709.     strcatbuff(LINE," -P ");
  1710.     strcatbuff(LINE,OPTIONproxy);
  1711.     strcatbuff(LINE,":");
  1712.     strcatbuff(LINE,OPTIONport);
  1713.   }
  1714.   
  1715.   if (strnotempty(LANGUAGE_ISO)) {
  1716.     strcatbuff(LINE," -%l \"");
  1717.     strcatbuff(LINE,LANGUAGE_ISO);
  1718.     if (strcmp(LANGUAGE_ISO,"en")!=0)
  1719.       strcatbuff(LINE,", en");
  1720.     strcatbuff(LINE,", *\"");
  1721.   }
  1722.   
  1723.   // mode spider, mettre aprËs options
  1724.   if (choixdeb[0]=='!') {
  1725.     strcatbuff(LINE," --testlinks");
  1726.   } else if (choixdeb[0]=='Y') {
  1727.     strcatbuff(LINE," --mirrorlinks");
  1728.   }
  1729.   
  1730.   // URLs!!
  1731.   strcatbuff(LINE," ");
  1732.   strcatbuff(LINE,OPTIONurl);
  1733.   
  1734.   // file list
  1735.   if ((int) strlen(OPTIONfilelist)>0) {
  1736.     strcatbuff(LINE," -%L \"");
  1737.     strcatbuff(LINE,OPTIONfilelist);
  1738.     strcatbuff(LINE,"\"");
  1739.   }
  1740.   
  1741.   // chemins
  1742.   if(strcmp(OPTIONpath,"")!=0) {
  1743.     strcatbuff(LINE," ");
  1744.     strcatbuff(LINE,"-O");
  1745.     strcatbuff(LINE," ");
  1746.     strcatbuff(LINE,OPTIONpath);
  1747.   }
  1748.   
  1749.   // buffer -> les + et -
  1750.   if(strcmp(buff_filtres,"")!=0) {
  1751.     //if(strcmp(diafiltre.m_url2 ,"")!=0) {
  1752.     strcatbuff(LINE," ");
  1753.     strcatbuff(LINE,buff_filtres );
  1754.   }
  1755.   
  1756.   // --assume
  1757.   if (strnotempty(buff_MIME)) {
  1758.     strcatbuff(LINE," ");
  1759.     strcatbuff(LINE,buff_MIME );
  1760.   }
  1761.   
  1762.   // ---
  1763.   
  1764.   //
  1765.   if (fp_debug) {
  1766.     fprintf(fp_debug,"Cleaning up command line and counting parameters\r\n");
  1767.     fflush(fp_debug);
  1768.   }
  1769.   //
  1770.   // Èpurer cr,lf,tab - double espace -> espace
  1771.   {
  1772.     char *a;
  1773.     while(a=strchr(LINE,9)) *a=' ';
  1774.     while(a=strchr(LINE,10)) *a=' ';
  1775.     while(a=strchr(LINE,13)) *a=' ';
  1776.   }
  1777.   
  1778.   char LINE_back[65535];
  1779.   strcpybuff(LINE_back,LINE);
  1780.   
  1781.   // couper en morceaux
  1782.   {
  1783.     char* p=LINE;
  1784.     argv[0]="winhttrack";
  1785.     do {
  1786.       argv[argc++]=p;
  1787.       p=next_token(p,0);    // prochain token
  1788.       if (p) {
  1789.         *p=0;    // octet nul (tableau)
  1790.         p++;
  1791.       }            
  1792.     } while(p!=NULL);
  1793.   }
  1794.   
  1795.   //
  1796.   if (fp_debug) {
  1797.     fprintf(fp_debug,"Checking doit.log\r\n");
  1798.     fflush(fp_debug);
  1799.   }
  1800.   //
  1801.   // Ok, on lance!
  1802.   if(!termine) {
  1803.     int result=0;
  1804.     {
  1805.       char path_log[HTS_URLMAXSIZE*2];
  1806.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1807.       if (strlen(path_log)>0)
  1808.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1809.           strcatbuff(path_log,"/");
  1810.         
  1811.         // on efface le doit.log, pour annuler les parametres anciens et en redÈfinir de nouveaux
  1812.         // c'est ici une logique qui diffËre de la version en ligne de commande
  1813.         //if ((fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))) {  // il existe dÈja un cache prÈcÈdent.. renommer
  1814.         if (fexist(fconcat(path_log,"hts-cache/new.ndx"))) {    // un cache est prÈsent
  1815.           if (fexist(fconcat(path_log,"hts-cache/doit.log")))
  1816.             remove(fconcat(path_log,"hts-cache/doit.log"));
  1817.           FILE* fp=fopen(fconcat(path_log,"hts-cache/doit.log"),"wb");
  1818.           if (fp) fclose(fp);
  1819.         }
  1820.         //}
  1821.     }
  1822.     
  1823.     
  1824.     // ---
  1825.     // LANCER LE MIROIR
  1826.     // ---
  1827.     //
  1828.     if (fp_debug) {
  1829.       fprintf(fp_debug,"Ready to call httrack engine, launching threads\r\n");
  1830.       fflush(fp_debug);
  1831.     }
  1832.     //
  1833. #if SHELL_MULTITHREAD
  1834.     Robot_params al;
  1835.     al.argc=argc;
  1836.     al.argv=argv;
  1837.     _beginthread( RunBackRobot     , 0, (void*) &al);
  1838.     //_beginthread( RefreshBackRobot , 0, NULL);
  1839.     
  1840.     //
  1841.     if (fp_debug) {
  1842.       fprintf(fp_debug,"Threads launched, displaying main dialog\r\n");
  1843.       fflush(fp_debug);
  1844.     }
  1845.     //
  1846.     // domodal du refresh
  1847.     /* XXC A SUPPRIMER */
  1848.     while(!termine) {
  1849.       Sleep(100);
  1850.     }
  1851.     //inprogress->DoModal();
  1852.     WHTT_LOCK();
  1853.     shell_terminated=1;
  1854.     result=HTTRACK_result;
  1855.     termine=1;  
  1856.     WHTT_UNLOCK();
  1857.     //
  1858.     if (fp_debug) {
  1859.       fprintf(fp_debug,"Main dialog exited\r\n");
  1860.       fflush(fp_debug);
  1861.     }
  1862.     //
  1863.     
  1864.     // non multithread
  1865. #else
  1866. #error "Non supportÈ"
  1867. #endif
  1868.  
  1869.     /* Aborted mirror or finished? */
  1870.     {
  1871.       char path_log[HTS_URLMAXSIZE*2];
  1872.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1873.       if (strlen(path_log)>0)
  1874.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1875.           strcatbuff(path_log,"/");
  1876.         if (soft_term_requested || termine_requested) {
  1877.           FILE* fp=fopen(fconcat(path_log,"hts-cache/interrupted.lock"),"wb");
  1878.           if (fp)
  1879.             fclose(fp);
  1880.         } else
  1881.           remove(fconcat(path_log,"hts-cache/interrupted.lock"));
  1882.     }
  1883.     
  1884.     //SetForegroundWindow();   // yop en premier plan!
  1885.     //
  1886.     if (fp_debug) {
  1887.       fprintf(fp_debug,"Displaying end dialog\r\n");
  1888.       fflush(fp_debug);
  1889.     }
  1890.     //
  1891.     /* New pannel */
  1892.     if (result) {      // erreur?
  1893.       strcpybuff(end_mirror_msg,LANG(LANG_F19 /*"A problem occured during the mirror\n  \"","Un problËme est survenu pendant le miroir\n  \""*/));
  1894.       strcatbuff(end_mirror_msg,"\"");
  1895.       strcatbuff(end_mirror_msg,hts_errmsg());
  1896.       strcatbuff(end_mirror_msg,"\"");
  1897.       strcatbuff(end_mirror_msg,LANG(LANG_F20 /*"\" \nDuring:\n  ","\" \nDurant:\n  "*/));
  1898.       strcatbuff(end_mirror_msg,"\"");
  1899.       strcatbuff(end_mirror_msg,LINE_back);
  1900.       strcatbuff(end_mirror_msg,"\"");
  1901.       strcatbuff(end_mirror_msg,LANG(LANG_F21 /*"\nSee the log file if necessary.\n\nClick OK to quit WinHTTrack.\n\nThanks for using WinHTTrack!","\nVoir le fichier log au besoin\n\nCliquez sur OK pour quitter WinHTTrack\n\nMerci d'utiliser WinHTTrack."*/));
  1902.       //AfxMessageBox(s,MB_OK+MB_ICONINFORMATION);
  1903.     } else {
  1904.       strcpybuff(end_mirror_msg,LANG(LANG_F22 /*"The mirror is finished.\nClick OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!","Le miroir est terminÈ\nCliquez sur OK pour quitter WinHTTrack\nVoir au besoin les fichiers d'audit pour vÈrifier que tout s'est bien passÈ\n\nMerci d'utiliser WinHTTrack!"*/));
  1905.       //AfxMessageBox("The mirror is finished.\nClic OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!",MB_OK+MB_ICONINFORMATION);
  1906.       //        ShellExecute(0,"open",,"","",);
  1907.     }
  1908. #if USE_RAS
  1909.     // erreur ras
  1910.     if (connected == -1)
  1911.       if ((int) strlen(connected_err) > 0)
  1912.         strcpybuff(end_mirror_msg,connected_err);
  1913. #endif
  1914.       {
  1915.         char pathlog[HTS_URLMAXSIZE*2];
  1916.         strcpybuff(pathlog,dialog0->GetPath());
  1917.         Ciplog form;
  1918.         if (strlen(pathlog)>0)
  1919.           if ((pathlog[strlen(pathlog)-1]!='/') && (pathlog[strlen(pathlog)-1]!='\\'))
  1920.             strcatbuff(pathlog,"/");
  1921.           // fichier log existe ou on est tÈlÈcommandÈ par un !
  1922.           if ( (fsize(fconcat(pathlog,"hts-err.txt")))>0) {
  1923.             strcatbuff(end_mirror_msg,LANG(LANG_F23 /*"\n\nTip: Click [View log file] to see warning or error messages","\n\nConseil: [Voir fichiers log] pour voir les erreurs et messages"*/));
  1924.           }
  1925.       }
  1926.       //this_Cinfoend->m_infoend = msg;
  1927.       inprogress->SendMessage(WM_USER + 4);      // avertir
  1928.       if (fp_debug) {
  1929.         fprintf(fp_debug,"DoModal end dialog, waiting\r\n");
  1930.         fflush(fp_debug);
  1931.       }
  1932.       /*
  1933.       if (info.DoModal() == IDC_NewProject) {     // relancer programme!
  1934.       // copie de onnewproject() de wid1::
  1935.       CWinApp* pApp = AfxGetApp();
  1936.       CString name = pApp->m_pszHelpFilePath;
  1937.       name=name.Left(name.GetLength()-4);
  1938.       name += ".EXE";
  1939.       ShellExecute(NULL,"open",name,"","",SW_RESTORE);    
  1940.       }
  1941.       */
  1942.       if (fp_debug) {
  1943.         fprintf(fp_debug,"Final info OK, leaving..\r\n");
  1944.         fflush(fp_debug);
  1945.       }
  1946.   }
  1947.   else {
  1948.   }
  1949.   
  1950. }
  1951.  
  1952. // int LANG_T(int);
  1953. // char* LANG(char* english,char* francais);
  1954.  
  1955.  
  1956. /* interface lang - lang_string="stringlang0\nstringlang1\n..laststring" */
  1957. void SetCombo(CWnd* _this,int id,char* lang_string) {
  1958.   CComboBox* combo = (CComboBox*) _this->GetDlgItem(id);
  1959.   CString st=lang_string;
  1960.   st.TrimLeft(); st.TrimRight();
  1961.   if (combo) {
  1962.     st+="\n";         /* end */
  1963.     combo->ResetContent();
  1964.     while(st.GetLength()) {
  1965.       int pos=st.Find('\n');
  1966.       CString item=st.Left(pos);
  1967.       st=st.Mid(pos+1);
  1968.       item.TrimLeft(); item.TrimRight();
  1969.       if (item.GetLength())
  1970.         combo->AddString(item);
  1971.     }
  1972.   }
  1973. }
  1974.  
  1975.  
  1976. // Ecriture profiles
  1977. char* profile_code(char* from) {
  1978.   static char buff[65535];
  1979.   int i;
  1980.   int j;
  1981.   for(i=0,j=0;i<(int) strlen(from);i++) {
  1982.     switch(from[i]) {
  1983.     case '%': 
  1984.       buff[j++]='%';
  1985.       buff[j++]='%';
  1986.       break;
  1987.     case '=': 
  1988.       buff[j++]='%';
  1989.       buff[j++]='3';
  1990.       buff[j++]='d';
  1991.       break;
  1992.     case 13:
  1993.       buff[j++]='%';
  1994.       buff[j++]='0';
  1995.       buff[j++]='d';
  1996.       break;
  1997.     case 10:
  1998.       buff[j++]='%';
  1999.       buff[j++]='0';
  2000.       buff[j++]='a';
  2001.       break;
  2002.     case 9:
  2003.       buff[j++]='%';
  2004.       buff[j++]='0';
  2005.       buff[j++]='9';
  2006.       break;
  2007.     default:
  2008.       buff[j++]=from[i];
  2009.       break;
  2010.     }
  2011.   }
  2012.   buff[j++]='\0';
  2013.   return buff;
  2014. }
  2015. char* profile_decode(char* from) {
  2016.   static char buff[2048];
  2017.   int i;
  2018.   int j;
  2019.   for(i=0,j=0;j<(int) strlen(from);i++) {  // oui oui
  2020.     if (from[j]=='%') {
  2021.       if (from[j+1]=='%') {
  2022.         buff[i]='%';
  2023.         j+=2;
  2024.       } else {
  2025.         if (strncmp(from+j+1,"0d",2)==0)
  2026.           buff[i]=13;
  2027.         else if (strncmp(from+j+1,"0a",2)==0)
  2028.           buff[i]=10;
  2029.         else if (strncmp(from+j+1,"09",2)==0)
  2030.           buff[i]=9;
  2031.         else if (strncmp(from+j+1,"3d",2)==0)
  2032.           buff[i]='=';
  2033.         else
  2034.           buff[i]=' ';
  2035.         j+=3;
  2036.       }
  2037.     } else
  2038.       buff[i]=from[j++];
  2039.   }
  2040.   buff[i++]='\0';
  2041.   return buff;
  2042. }
  2043. //
  2044. // Ecriture/Lecture profiles
  2045. int MyWriteProfileInt(CString path,CString dummy,CString name,int value) {
  2046.   if (path.IsEmpty()) {
  2047.     CWinApp* pApp = AfxGetApp();
  2048.     pApp->WriteProfileInt(dummy,name,value);
  2049.   } else if (path=="<mem>") {       // buffer
  2050.     tmpm.setInt(name,value);
  2051.     return 0;
  2052.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2053.     if (tmpf) {
  2054.       return MyWriteProfileIntFile(tmpf,dummy,name,value);
  2055.     }
  2056.   } else {
  2057.     FILE* fp = fopen(path,"ab");
  2058.     if (fp) {
  2059.       int r=MyWriteProfileIntFile(fp,dummy,name,value);
  2060.       /*
  2061.       fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2062.       */
  2063.       fclose(fp);
  2064.       return r;
  2065.     }
  2066.   }
  2067.   return 0;
  2068. }
  2069. int MyWriteProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2070.   if (fp) {
  2071.     fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2072.   }
  2073.   return 0;
  2074. }
  2075. int MyWriteProfileString(CString path,CString dummy,CString name,CString value) {
  2076.   if (path.IsEmpty()) {
  2077.     CWinApp* pApp = AfxGetApp();
  2078.     char *tempo;
  2079.     tempo=(char*) malloc(strlen(value)+1);
  2080.     if (tempo) {
  2081.       strcpybuff(tempo,value);
  2082.       pApp->WriteProfileString(dummy,name,profile_code(tempo));
  2083.     } else
  2084.       return -1;      // error
  2085.   } else if (path=="<mem>") {       // buffer
  2086.     tmpm.setString(name,value);
  2087.     return 0;
  2088.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2089.     if (tmpf) {
  2090.       return MyWriteProfileStringFile(tmpf,dummy,name,value);
  2091.     }
  2092.   } else {
  2093.     FILE* fp = fopen(path,"ab");
  2094.     if (fp) {
  2095.       int r=MyWriteProfileStringFile(fp,dummy,name,value);
  2096.       /*
  2097.       char *tempo;
  2098.       tempo=(char*) malloc(strlen(value)+1);
  2099.       if (tempo) {
  2100.       strcpybuff(tempo,value);
  2101.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2102.       fclose(fp);
  2103.       free(tempo);
  2104.       } else
  2105.       return -1;      // error
  2106.       */
  2107.       fclose(fp);
  2108.       return r;
  2109.     }
  2110.   }
  2111.   return 0;
  2112. }
  2113. int MyWriteProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2114.   if (fp) {
  2115.     char *tempo;
  2116.     tempo=(char*) malloc(strlen(value)+1);
  2117.     if (tempo) {
  2118.       strcpybuff(tempo,value);
  2119.       fprintf(fp,"%s=%s\x0d\x0a",name,profile_code(tempo));
  2120.       free(tempo);
  2121.     } else
  2122.       return -1;      // error
  2123.   }
  2124.   return 0;
  2125. }
  2126. //
  2127. // lecture
  2128. int MyGetProfileInt(CString path,CString dummy,CString name,int value) {
  2129.   if (path.IsEmpty()) {
  2130.     CWinApp* pApp = AfxGetApp();
  2131.     return pApp->GetProfileInt(dummy,name,value);
  2132.   } else if (path=="<mem>") {       // buffer
  2133.     return tmpm.getInt(name,value);
  2134.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2135.     if (tmpf) {
  2136.       return MyGetProfileIntFile(tmpf,dummy,name,value);
  2137.     } else return value;
  2138.   } else {
  2139.     FILE* fp = fopen(path,"rb");
  2140.     if (fp) {
  2141.       int r=MyGetProfileIntFile(fp,dummy,name,value);
  2142.       /*
  2143.       char srch[256];
  2144.       sprintf(srch,"%s=",name);
  2145.       while(!feof(fp)) {
  2146.       char s[HTS_URLMAXSIZE*2];
  2147.       linput(fp,s,1020);
  2148.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2149.       int val;
  2150.       if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2151.       return val;
  2152.       else
  2153.       return value;
  2154.       }
  2155.       }
  2156.       fclose(fp);
  2157.       return value;
  2158.       */
  2159.       fclose(fp);
  2160.       return r;
  2161.     } else return value;
  2162.   }
  2163. }
  2164. int MyGetProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2165.   if (fp) {
  2166.     char srch[256];
  2167.     fseek(fp,0,SEEK_SET);
  2168.     sprintf(srch,"%s=",name);
  2169.     while(!feof(fp)) {
  2170.       char s[2048]; s[0]='\0';
  2171.       linput(fp,s,2000);
  2172.       if (strlen(s)==0)     // EOF
  2173.         return value;
  2174.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2175.         int val;
  2176.         if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2177.           return val;
  2178.         else
  2179.           return value;
  2180.       }
  2181.     }
  2182.     return value;
  2183.   } else return value;
  2184. }
  2185. CString MyGetProfileString(CString path,CString dummy,CString name,CString value) {
  2186.   if (path.IsEmpty()) {
  2187.     CWinApp* pApp = AfxGetApp();
  2188.     char tempo[32768];
  2189.     char value_default[32768];
  2190.     strcpybuff(value_default,value);
  2191.     strcpybuff(tempo,pApp->GetProfileString(dummy,name,profile_code(value_default)));
  2192.     return profile_decode(tempo);
  2193.   } else if (path=="<mem>") {       // buffer
  2194.     return tmpm.getString(name,value);
  2195.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2196.     if (tmpf) {
  2197.       return MyGetProfileStringFile(tmpf,dummy,name,value);
  2198.     } else return value;
  2199.   } else {
  2200.     FILE* fp = fopen(path,"rb");
  2201.     if (fp) {
  2202.       CString st=MyGetProfileStringFile(fp,dummy,name,value);
  2203.       /*
  2204.       char srch[256];
  2205.       sprintf(srch,"%s",name);
  2206.       strcatbuff(srch,"=");
  2207.       while(!feof(fp)) {
  2208.       char s[32768];
  2209.       linput(fp,s,32000);
  2210.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2211.       return profile_decode(s+strlen(srch));
  2212.       }
  2213.       }
  2214.       fclose(fp);
  2215.       return value;
  2216.       */
  2217.       fclose(fp);
  2218.       return st;
  2219.     } else return value;
  2220.   }
  2221. }
  2222. CString MyGetProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2223.   if (fp) {
  2224.     char srch[256];
  2225.     fseek(fp,0,SEEK_SET);
  2226.     sprintf(srch,"%s",name);
  2227.     strcatbuff(srch,"=");
  2228.     while(!feof(fp)) {
  2229.       char s[32768]; s[0]='\0';
  2230.       linput(fp,s,32000);
  2231.       if (strlen(s)==0)     // EOF
  2232.         return value;
  2233.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2234.         return profile_decode(s+strlen(srch));
  2235.       }
  2236.     }
  2237.     return value;
  2238.   } else return value;
  2239. }
  2240.  
  2241. //
  2242. // Get_profile et Write_profile eux mÍmes
  2243. //
  2244. // path="" -> Ècrire dans la base (default)
  2245. // path="<tmp>" -> Ècrire dans le fichier tempo commun
  2246. // path="<mem>" -> Ècrire dans le buffer tempo commun
  2247. // path="<null>" -> lire default (illÈgal en Ècriture)
  2248. void Write_profile(CString path,int load_path) {
  2249.   CWaitCursor wait;
  2250.   CString strSection       = "OptionsValues";
  2251.   CString st;
  2252.   int n;
  2253.   
  2254.   // Fichier tempo ou fichier?
  2255.   if (path=="<tmp>") {     // fichier temporaire
  2256.     if (tmpf)
  2257.       fclose(tmpf);
  2258.     tmpf=tmpfile();
  2259.     if (!tmpf)
  2260.       return;
  2261.   } else if (path=="<mem>") {     // buffer temporaire
  2262.     tmpm.deleteAll();
  2263.   } else if (!(path.IsEmpty())) {
  2264.     FILE *fp=fopen(path,"wb");
  2265.     if (fp) 
  2266.       fclose(fp);
  2267.   }
  2268.   
  2269.   //if (dialog3.m_hWnd == NULL) {    // pas initialisÈ
  2270.   if (maintab->m_hWnd == NULL) {    // pas initialisÈ
  2271.     // checkboxes
  2272.     MyWriteProfileInt(path,strSection, "Near",maintab->m_option1.m_link);
  2273.     MyWriteProfileInt(path,strSection, "Test",maintab->m_option1.m_testall);
  2274.     MyWriteProfileInt(path,strSection, "ParseAll",maintab->m_option1.m_parseall);
  2275.     MyWriteProfileInt(path,strSection, "HTMLFirst",maintab->m_option1.m_htmlfirst);
  2276.     MyWriteProfileInt(path,strSection, "Cache",maintab->m_option3.m_cache);
  2277.     MyWriteProfileInt(path,strSection, "NoRecatch",maintab->m_option9.m_norecatch);
  2278.     MyWriteProfileInt(path,strSection, "Dos",
  2279.       ((maintab->m_option2.m_dos)?1:0)
  2280.       +
  2281.       (((maintab->m_option2.m_iso9660)?1:0)<<1)
  2282.       );
  2283.     MyWriteProfileInt(path,strSection, "Index",maintab->m_option9.m_index);
  2284.     MyWriteProfileInt(path,strSection, "WordIndex",maintab->m_option9.m_index2);
  2285.     MyWriteProfileInt(path,strSection, "Log",maintab->m_option9.m_logf);
  2286.     MyWriteProfileInt(path,strSection, "RemoveTimeout",maintab->m_option4.m_remt);
  2287.     MyWriteProfileInt(path,strSection, "RemoveRateout",maintab->m_option4.m_rems);
  2288.     MyWriteProfileInt(path,strSection, "FollowRobotsTxt",maintab->m_option8.m_robots);
  2289.     MyWriteProfileInt(path,strSection, "NoErrorPages",maintab->m_option2.m_errpage);
  2290.     MyWriteProfileInt(path,strSection, "NoExternalPages",maintab->m_option2.m_external);
  2291.     MyWriteProfileInt(path,strSection, "NoPwdInPages",maintab->m_option2.m_hidepwd);
  2292.     MyWriteProfileInt(path,strSection, "NoQueryStrings",maintab->m_option2.m_hidequery);
  2293.     MyWriteProfileInt(path,strSection, "NoPurgeOldFiles",maintab->m_option2.m_nopurge);
  2294.     MyWriteProfileInt(path,strSection, "Cookies",maintab->m_option8.m_cookies);
  2295.     MyWriteProfileInt(path,strSection, "CheckType",maintab->m_option8.m_checktype);
  2296.     MyWriteProfileInt(path,strSection, "ParseJava",maintab->m_option8.m_parsejava);
  2297.     MyWriteProfileInt(path,strSection, "HTTP10",maintab->m_option8.m_http10);
  2298.     MyWriteProfileInt(path,strSection, "TolerantRequests",maintab->m_option8.m_toler);
  2299.     MyWriteProfileInt(path,strSection, "UpdateHack",maintab->m_option8.m_updhack);
  2300.     MyWriteProfileInt(path,strSection, "StoreAllInCache",maintab->m_option9.m_Cache2);
  2301.     MyWriteProfileInt(path,strSection, "LogType",maintab->m_option9.m_logtype);
  2302.     MyWriteProfileInt(path,strSection, "UseHTTPProxyForFTP",maintab->m_option10.m_ftpprox);
  2303.     
  2304.     // menus
  2305.     MyWriteProfileInt(path,strSection, "Build",maintab->m_option2.m_build);
  2306.     MyWriteProfileInt(path,strSection, "PrimaryScan",maintab->m_option3.m_filter);
  2307.     MyWriteProfileInt(path,strSection, "Travel",maintab->m_option3.m_travel);
  2308.     MyWriteProfileInt(path,strSection, "GlobalTravel",maintab->m_option3.m_travel2);
  2309.     MyWriteProfileInt(path,strSection, "RewriteLinks",maintab->m_option3.m_travel3);
  2310.     MyWriteProfileString(path,strSection, "BuildString",maintab->m_option2.Bopt.m_BuildString);
  2311.     
  2312.     // champs
  2313.     MyWriteProfileString(path,strSection, "MaxHtml",maintab->m_option5.m_maxhtml);
  2314.     MyWriteProfileString(path,strSection, "MaxOther",maintab->m_option5.m_othermax);
  2315.     MyWriteProfileString(path,strSection, "MaxAll",maintab->m_option5.m_sizemax);
  2316.     MyWriteProfileString(path,strSection, "MaxWait",maintab->m_option5.m_pausebytes);
  2317.     MyWriteProfileString(path,strSection, "Sockets",maintab->m_option4.m_connexion);
  2318.     MyWriteProfileString(path,strSection, "Retry",maintab->m_option4.m_retry);
  2319.     MyWriteProfileString(path,strSection, "MaxTime",maintab->m_option5.m_maxtime);
  2320.     MyWriteProfileString(path,strSection, "TimeOut",maintab->m_option4.m_timeout);
  2321.     MyWriteProfileString(path,strSection, "RateOut",maintab->m_option4.m_rate);
  2322.     MyWriteProfileString(path,strSection, "UserID",maintab->m_option6.m_user);
  2323.     MyWriteProfileString(path,strSection, "Footer",maintab->m_option6.m_footer);
  2324.     MyWriteProfileString(path,strSection, "MaxRate",maintab->m_option5.m_maxrate);
  2325.     MyWriteProfileString(path,strSection, "WildCardFilters",maintab->m_option7.m_url2);
  2326.     MyWriteProfileString(path,strSection, "Proxy",maintab->m_option10.m_proxy);
  2327.     MyWriteProfileString(path,strSection, "Port",maintab->m_option10.m_port);
  2328.     MyWriteProfileString(path,strSection, "Depth",maintab->m_option5.m_depth);
  2329.     MyWriteProfileString(path,strSection, "ExtDepth",maintab->m_option5.m_depth2);
  2330.     MyWriteProfileString(path,strSection, "MaxConn",maintab->m_option5.m_maxconn);    
  2331.     MyWriteProfileString(path,strSection, "MaxLinks",maintab->m_option5.m_maxlinks);    
  2332.     
  2333.     // 11
  2334.     MyWriteProfileString(path,strSection, "MIMEDefsExt1",maintab->m_option11.m_ext1);    
  2335.     MyWriteProfileString(path,strSection, "MIMEDefsExt2",maintab->m_option11.m_ext2);    
  2336.     MyWriteProfileString(path,strSection, "MIMEDefsExt3",maintab->m_option11.m_ext3);    
  2337.     MyWriteProfileString(path,strSection, "MIMEDefsExt4",maintab->m_option11.m_ext4);    
  2338.     MyWriteProfileString(path,strSection, "MIMEDefsExt5",maintab->m_option11.m_ext5);    
  2339.     MyWriteProfileString(path,strSection, "MIMEDefsExt6",maintab->m_option11.m_ext6);    
  2340.     MyWriteProfileString(path,strSection, "MIMEDefsExt7",maintab->m_option11.m_ext7);    
  2341.     MyWriteProfileString(path,strSection, "MIMEDefsExt8",maintab->m_option11.m_ext8);    
  2342.     MyWriteProfileString(path,strSection, "MIMEDefsMime1",maintab->m_option11.m_mime1);    
  2343.     MyWriteProfileString(path,strSection, "MIMEDefsMime2",maintab->m_option11.m_mime2);    
  2344.     MyWriteProfileString(path,strSection, "MIMEDefsMime3",maintab->m_option11.m_mime3);    
  2345.     MyWriteProfileString(path,strSection, "MIMEDefsMime4",maintab->m_option11.m_mime4);    
  2346.     MyWriteProfileString(path,strSection, "MIMEDefsMime5",maintab->m_option11.m_mime5);    
  2347.     MyWriteProfileString(path,strSection, "MIMEDefsMime6",maintab->m_option11.m_mime6);    
  2348.     MyWriteProfileString(path,strSection, "MIMEDefsMime7",maintab->m_option11.m_mime7);    
  2349.     MyWriteProfileString(path,strSection, "MIMEDefsMime8",maintab->m_option11.m_mime8);    
  2350.   } else {
  2351.     // checkboxes
  2352.     // 1
  2353.     n=maintab->m_option1.IsDlgButtonChecked(IDC_link);
  2354.     MyWriteProfileInt(path,strSection,"Near", n);
  2355.     n=maintab->m_option1.IsDlgButtonChecked(IDC_testall);
  2356.     MyWriteProfileInt(path,strSection,"Test", n);
  2357.     n=maintab->m_option1.IsDlgButtonChecked(IDC_parseall);
  2358.     MyWriteProfileInt(path,strSection,"ParseAll", n);
  2359.     n=maintab->m_option1.IsDlgButtonChecked(IDC_htmlfirst);
  2360.     MyWriteProfileInt(path,strSection,"HTMLFirst", n);
  2361.     // 2
  2362.     n=maintab->m_option3.IsDlgButtonChecked(IDC_Cache);
  2363.     MyWriteProfileInt(path,strSection,"Cache", n);
  2364.     n=maintab->m_option2.IsDlgButtonChecked(IDC_norecatch);
  2365.     MyWriteProfileInt(path,strSection,"NoRecatch", n);
  2366.     n = ((maintab->m_option2.IsDlgButtonChecked(IDC_dos))?1:0)
  2367.       + ((maintab->m_option2.IsDlgButtonChecked(IDC_iso9660)?1:0)<<1);
  2368.     MyWriteProfileInt(path,strSection,"Dos", n);
  2369.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index);
  2370.     MyWriteProfileInt(path,strSection,"Index", n);
  2371.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index2);
  2372.     MyWriteProfileInt(path,strSection,"WordIndex", n);
  2373.     n=maintab->m_option2.IsDlgButtonChecked(IDC_logf);
  2374.     MyWriteProfileInt(path,strSection,"Log", n);
  2375.     n=maintab->m_option2.IsDlgButtonChecked(IDC_errpage);
  2376.     MyWriteProfileInt(path,strSection,"NoErrorPages", n);
  2377.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidepwd);
  2378.     MyWriteProfileInt(path,strSection,"NoPwdInPages", n);
  2379.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidequery);
  2380.     MyWriteProfileInt(path,strSection,"NoQueryStrings", n);
  2381.     n=maintab->m_option2.IsDlgButtonChecked(IDC_external);
  2382.     MyWriteProfileInt(path,strSection,"NoExternalPages", n);
  2383.     n=maintab->m_option2.IsDlgButtonChecked(IDC_nopurge);
  2384.     MyWriteProfileInt(path,strSection,"NoPurgeOldFiles", n);
  2385.     if ((n=maintab->m_option2.m_ctl_build.GetCurSel()) != CB_ERR)
  2386.       MyWriteProfileInt(path,strSection, "Build", n);
  2387.     st = maintab->m_option2.Bopt.m_BuildString;
  2388.     if (st.GetLength()>0)
  2389.       MyWriteProfileString(path,strSection, "BuildString",st);
  2390.     // 3
  2391.     // menus
  2392.     if ((n=maintab->m_option3.m_ctl_filter.GetCurSel()) != CB_ERR)
  2393.       MyWriteProfileInt(path,strSection, "PrimaryScan", n);
  2394.     if ((n=maintab->m_option3.m_ctl_travel.GetCurSel()) != CB_ERR)
  2395.       MyWriteProfileInt(path,strSection, "Travel", n);
  2396.     if ((n=maintab->m_option3.m_ctl_travel2.GetCurSel()) != CB_ERR)
  2397.       MyWriteProfileInt(path,strSection, "GlobalTravel", n);
  2398.     if ((n=maintab->m_option3.m_ctl_travel3.GetCurSel()) != CB_ERR)
  2399.       MyWriteProfileInt(path,strSection, "RewriteLinks", n);
  2400.     //
  2401.     maintab->m_option8.GetDlgItemText(IDC_robots,st);
  2402.     MyWriteProfileString(path,strSection, "FollowRobotsTxt", st);
  2403.     // 4
  2404.     maintab->m_option4.GetDlgItemText(IDC_connexion,st);
  2405.     MyWriteProfileString(path,strSection, "Sockets", st);
  2406.     maintab->m_option4.GetDlgItemText(IDC_timeout,st);
  2407.     MyWriteProfileString(path,strSection, "TimeOut", st);
  2408.     n=maintab->m_option4.IsDlgButtonChecked(IDC_remt);
  2409.     MyWriteProfileInt(path,strSection,"RemoveTimeout", n);
  2410.     maintab->m_option4.GetDlgItemText(IDC_retry,st);
  2411.     MyWriteProfileString(path,strSection, "Retry", st);
  2412.     maintab->m_option4.GetDlgItemText(IDC_rate,st);
  2413.     MyWriteProfileString(path,strSection, "RateOut", st);
  2414.     n=maintab->m_option4.IsDlgButtonChecked(IDC_rems);
  2415.     MyWriteProfileInt(path,strSection,"RemoveRateout", n);
  2416.     // 5
  2417.     maintab->m_option5.GetDlgItemText(IDC_maxhtml,st);
  2418.     MyWriteProfileString(path,strSection, "MaxHtml", st);
  2419.     maintab->m_option5.GetDlgItemText(IDC_othermax,st);
  2420.     MyWriteProfileString(path,strSection, "MaxOther", st);
  2421.     maintab->m_option5.GetDlgItemText(IDC_sizemax,st);
  2422.     MyWriteProfileString(path,strSection, "MaxAll", st);
  2423.     maintab->m_option5.GetDlgItemText(IDC_pausebytes,st);
  2424.     MyWriteProfileString(path,strSection, "MaxWait", st);
  2425.     maintab->m_option5.GetDlgItemText(IDC_maxtime,st);
  2426.     MyWriteProfileString(path,strSection, "MaxTime", st);
  2427.     maintab->m_option5.GetDlgItemText(IDC_maxrate,st);
  2428.     MyWriteProfileString(path,strSection, "MaxRate", st);
  2429.     maintab->m_option5.GetDlgItemText(IDC_depth,st);
  2430.     MyWriteProfileString(path,strSection,"Depth",st);
  2431.     maintab->m_option5.GetDlgItemText(IDC_depth2,st);
  2432.     MyWriteProfileString(path,strSection,"ExtDepth",st);
  2433.     maintab->m_option5.GetDlgItemText(IDC_maxconn,st);
  2434.     MyWriteProfileString(path,strSection, "MaxConn", st);
  2435.     maintab->m_option5.GetDlgItemText(IDC_maxlinks,st);
  2436.     MyWriteProfileString(path,strSection, "MaxLinks", st);
  2437.     // 6
  2438.     maintab->m_option6.GetDlgItemText(IDC_user,st);
  2439.     MyWriteProfileString(path,strSection, "UserID", st);
  2440.     maintab->m_option6.GetDlgItemText(IDC_footer,st);
  2441.     MyWriteProfileString(path,strSection, "Footer", st);
  2442.     // 7
  2443.     maintab->m_option7.GetDlgItemText(IDC_URL2,st);
  2444.     MyWriteProfileString(path,strSection, "WildCardFilters", st);
  2445.     // 8
  2446.     maintab->m_option8.GetDlgItemText(IDC_cookies,st);
  2447.     MyWriteProfileString(path,strSection, "Cookies", st);
  2448.     maintab->m_option8.GetDlgItemText(IDC_checktype,st);
  2449.     MyWriteProfileString(path,strSection, "CheckType", st);
  2450.     n=maintab->m_option8.IsDlgButtonChecked(IDC_parsejava);
  2451.     MyWriteProfileInt(path,strSection, "ParseJava", n);
  2452.     n=maintab->m_option8.IsDlgButtonChecked(IDC_http10);
  2453.     MyWriteProfileInt(path,strSection, "HTTP10", n);
  2454.     n=maintab->m_option8.IsDlgButtonChecked(IDC_toler);
  2455.     MyWriteProfileInt(path,strSection, "TolerantRequests", n);
  2456.     n=maintab->m_option8.IsDlgButtonChecked(IDC_updhack);
  2457.     MyWriteProfileInt(path,strSection, "UpdateHack", n);
  2458.     // 9
  2459.     maintab->m_option9.GetDlgItemText(IDC_Cache2,st);
  2460.     MyWriteProfileString(path,strSection, "StoreAllInCache", st);
  2461.     maintab->m_option9.GetDlgItemText(IDC_logtype,st);
  2462.     MyWriteProfileString(path,strSection, "LogType", st);
  2463.     // 10
  2464.     maintab->m_option10.GetDlgItemText(IDC_prox,st);
  2465.     MyWriteProfileString(path,strSection,"Proxy",st);
  2466.     maintab->m_option10.GetDlgItemText(IDC_proxport,st);
  2467.     MyWriteProfileString(path,strSection,"Port",st);
  2468.     n=maintab->m_option10.IsDlgButtonChecked(IDC_ftpprox);
  2469.     MyWriteProfileInt(path,strSection,"UseHTTPProxyForFTP", n);
  2470.     
  2471.     // 11
  2472.     maintab->m_option11.GetDlgItemText(IDC_ext1,st); MyWriteProfileString(path,strSection,"MIMEDefsExt1",st);
  2473.     maintab->m_option11.GetDlgItemText(IDC_ext2,st); MyWriteProfileString(path,strSection,"MIMEDefsExt2",st);
  2474.     maintab->m_option11.GetDlgItemText(IDC_ext3,st); MyWriteProfileString(path,strSection,"MIMEDefsExt3",st);
  2475.     maintab->m_option11.GetDlgItemText(IDC_ext4,st); MyWriteProfileString(path,strSection,"MIMEDefsExt4",st);
  2476.     maintab->m_option11.GetDlgItemText(IDC_ext5,st); MyWriteProfileString(path,strSection,"MIMEDefsExt5",st);
  2477.     maintab->m_option11.GetDlgItemText(IDC_ext6,st); MyWriteProfileString(path,strSection,"MIMEDefsExt6",st);
  2478.     maintab->m_option11.GetDlgItemText(IDC_ext7,st); MyWriteProfileString(path,strSection,"MIMEDefsExt7",st);
  2479.     maintab->m_option11.GetDlgItemText(IDC_ext8,st); MyWriteProfileString(path,strSection,"MIMEDefsExt8",st);
  2480.     maintab->m_option11.GetDlgItemText(IDC_mime1,st); MyWriteProfileString(path,strSection,"MIMEDefsMime1",st);
  2481.     maintab->m_option11.GetDlgItemText(IDC_mime2,st); MyWriteProfileString(path,strSection,"MIMEDefsMime2",st);
  2482.     maintab->m_option11.GetDlgItemText(IDC_mime3,st); MyWriteProfileString(path,strSection,"MIMEDefsMime3",st);
  2483.     maintab->m_option11.GetDlgItemText(IDC_mime4,st); MyWriteProfileString(path,strSection,"MIMEDefsMime4",st);
  2484.     maintab->m_option11.GetDlgItemText(IDC_mime5,st); MyWriteProfileString(path,strSection,"MIMEDefsMime5",st);
  2485.     maintab->m_option11.GetDlgItemText(IDC_mime6,st); MyWriteProfileString(path,strSection,"MIMEDefsMime6",st);
  2486.     maintab->m_option11.GetDlgItemText(IDC_mime7,st); MyWriteProfileString(path,strSection,"MIMEDefsMime7",st);
  2487.     maintab->m_option11.GetDlgItemText(IDC_mime8,st); MyWriteProfileString(path,strSection,"MIMEDefsMime8",st);
  2488.   }
  2489.   // liens, jokers etc. si mirror merge
  2490.   if (!(path.IsEmpty())) {
  2491.     if (dialog1->m_hWnd == NULL) {    // pas initialisÈ
  2492.       //MyWriteProfileString(path,strSection,"CurrentDepth",dialog1->m_depth);
  2493.       MyWriteProfileString(path,strSection,"CurrentUrl",dialog1->m_urls);
  2494.       if (dialog1->m_todo >= 0)
  2495.         MyWriteProfileInt(path, strSection,"CurrentAction", dialog1->m_todo);
  2496.       //
  2497.       MyWriteProfileString(path,strSection,"CurrentURLList",dialog1->m_filelist);
  2498.       
  2499.       //if (load_path) {
  2500.       //MyWriteProfileString(path,strSection,"CurrentPath1",dialog0->GetPath());
  2501.       //MyWriteProfileString(path,strSection,"CurrentPath2",dialog0->GetPath());
  2502.       //}
  2503.     } else {
  2504.       //dialog1->GetDlgItemText(IDC_depth,st);
  2505.       //MyWriteProfileString(path,strSection,"CurrentDepth",st);
  2506.       dialog1->GetDlgItemText(IDC_URL,st);
  2507.       MyWriteProfileString(path,strSection,"CurrentUrl",st);
  2508.       if ((n=dialog1->m_ctl_todo.GetCurSel()) != CB_ERR)
  2509.         MyWriteProfileInt(path,strSection, "CurrentAction", n);
  2510.       //
  2511.       dialog1->GetDlgItemText(IDC_filelist,st);
  2512.       MyWriteProfileString(path,strSection,"CurrentURLList",st);
  2513.       //
  2514.       //if (load_path) {
  2515.       //dialog1->GetDlgItemText(IDC_pathlog,st);
  2516.       //MyWriteProfileString(path,strSection,"CurrentPath1",st);
  2517.       //dialog1->GetDlgItemText(IDC_pthmir,st);
  2518.       //MyWriteProfileString(path,strSection,"CurrentPath2",st);
  2519.       //}
  2520.     }
  2521.   }
  2522. }
  2523. // path="" -> lire dans la base (default)
  2524. //if not exist: do not load anything but patches projname&co
  2525. void Read_profile(CString path,int load_path) {
  2526.   CWaitCursor wait;
  2527.   CString strSection       = "OptionsValues";
  2528.   CString st;
  2529.   
  2530.   // VÈrification <tmp>
  2531.   if (path=="<tmp>") {     // fichier temporaire
  2532.     if (!tmpf)
  2533.       return;
  2534.     else
  2535.       fflush(tmpf);
  2536.   } else if (path=="<null>") {     // options par dÈfaut
  2537.     path="<mem>";
  2538.     tmpm.deleteAll();              // effacer
  2539.   } else {
  2540.     int pos=path.ReverseFind('\\');
  2541.     if (pos>=0) {
  2542.       CString dir=path.Left(pos);           // enlever winprofile.ini
  2543.       pos=dir.ReverseFind('\\');
  2544.       if (pos>=0) {
  2545.         dir=dir.Left(pos);                  // enlever hts-cache
  2546.         pos=dir.ReverseFind('\\');
  2547.         if (pos>=0) {
  2548.           dialog0->m_projname=dir.Mid(pos+1);
  2549.           dialog0->m_projpath=dir.Left(pos);
  2550.           /*
  2551.           if (this_CWizTab)
  2552.           this_CWizTab->SetActivePage(2);     // page 3
  2553.           */
  2554.         }
  2555.       }
  2556.     }
  2557.   }
  2558.   
  2559.   // checkboxes
  2560.   maintab->m_option1.m_link      = MyGetProfileInt(path,strSection, "Near",0);
  2561.   maintab->m_option1.m_testall   = MyGetProfileInt(path,strSection, "Test",0);
  2562.   maintab->m_option1.m_parseall  = MyGetProfileInt(path,strSection, "ParseAll",1);
  2563.   maintab->m_option1.m_htmlfirst = MyGetProfileInt(path,strSection, "HTMLFirst",0);
  2564.   maintab->m_option3.m_cache     = MyGetProfileInt(path,strSection, "Cache",1);
  2565.   maintab->m_option9.m_norecatch = MyGetProfileInt(path,strSection, "NoRecatch",0);
  2566.   maintab->m_option2.m_dos       = (MyGetProfileInt(path,strSection, "Dos",0) & 1);
  2567.   maintab->m_option2.m_iso9660   = ((MyGetProfileInt(path,strSection, "Dos",0) & 2)>>1);
  2568.   maintab->m_option9.m_index     = MyGetProfileInt(path,strSection, "Index",1);
  2569.   maintab->m_option9.m_index2    = MyGetProfileInt(path,strSection, "WordIndex",0);
  2570.   maintab->m_option9.m_logf      = MyGetProfileInt(path,strSection, "Log",1);
  2571.   maintab->m_option4.m_remt      = MyGetProfileInt(path,strSection, "RemoveTimeout",0);
  2572.   maintab->m_option4.m_rems      = MyGetProfileInt(path,strSection, "RemoveRateout",0);
  2573.   maintab->m_option8.m_robots    = MyGetProfileInt(path,strSection, "FollowRobotsTxt",2);
  2574.   maintab->m_option2.m_errpage   = MyGetProfileInt(path,strSection, "NoErrorPages",0);
  2575.   maintab->m_option2.m_external  = MyGetProfileInt(path,strSection, "NoExternalPages",0);
  2576.   maintab->m_option2.m_hidepwd   = MyGetProfileInt(path,strSection, "NoPwdInPages",0);
  2577.   maintab->m_option2.m_hidequery = MyGetProfileInt(path,strSection, "NoQueryStrings",0);
  2578.   maintab->m_option2.m_nopurge   = MyGetProfileInt(path,strSection, "NoPurgeOldFiles",0);
  2579.   maintab->m_option8.m_cookies    = MyGetProfileInt(path,strSection, "Cookies",1);
  2580.   maintab->m_option8.m_checktype  = MyGetProfileInt(path,strSection, "CheckType",1);
  2581.   maintab->m_option8.m_parsejava  = MyGetProfileInt(path,strSection, "ParseJava",1);
  2582.   maintab->m_option8.m_toler      = MyGetProfileInt(path,strSection, "TolerantRequests",0);
  2583.   maintab->m_option8.m_updhack    = MyGetProfileInt(path,strSection, "UpdateHack",1);
  2584.   maintab->m_option8.m_http10     = MyGetProfileInt(path,strSection, "HTTP10",0);
  2585.   maintab->m_option9.m_Cache2     = MyGetProfileInt(path,strSection, "StoreAllInCache",0);
  2586.   maintab->m_option9.m_logtype    = MyGetProfileInt(path,strSection, "LogType",0);
  2587.   
  2588.   // menus
  2589.   maintab->m_option2.m_build   = MyGetProfileInt(path,strSection, "Build",0);
  2590.   maintab->m_option3.m_filter  = MyGetProfileInt(path,strSection, "PrimaryScan",3);
  2591.   maintab->m_option3.m_travel  = MyGetProfileInt(path,strSection, "Travel",1);
  2592.   maintab->m_option3.m_travel2 = MyGetProfileInt(path,strSection, "GlobalTravel",0);
  2593.   maintab->m_option3.m_travel3 = MyGetProfileInt(path,strSection, "RewriteLinks",0);
  2594.   maintab->m_option2.Bopt.m_BuildString = MyGetProfileString(path,strSection, "BuildString","%h%p/%n%q.%t");
  2595.   
  2596.   // champs
  2597.   maintab->m_option5.m_maxhtml =  MyGetProfileString(path,strSection, "MaxHtml");
  2598.   maintab->m_option5.m_othermax=  MyGetProfileString(path,strSection, "MaxOther");
  2599.   maintab->m_option5.m_sizemax =  MyGetProfileString(path,strSection, "MaxAll");
  2600.   maintab->m_option5.m_pausebytes=MyGetProfileString(path,strSection, "MaxWait");  
  2601.   maintab->m_option4.m_connexion= MyGetProfileString(path,strSection, "Sockets");
  2602.   maintab->m_option4.m_retry   =  MyGetProfileString(path,strSection, "Retry");
  2603.   maintab->m_option5.m_maxtime =  MyGetProfileString(path,strSection, "MaxTime");
  2604.   maintab->m_option4.m_timeout =  MyGetProfileString(path,strSection, "TimeOut");
  2605.   maintab->m_option4.m_rate    =  MyGetProfileString(path,strSection, "RateOut");
  2606.   maintab->m_option6.m_user    =  MyGetProfileString(path,strSection, "UserID","Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)");
  2607.   maintab->m_option6.m_footer  =  MyGetProfileString(path,strSection, "Footer",HTS_DEFAULT_FOOTER);
  2608.   maintab->m_option5.m_maxrate =  MyGetProfileString(path,strSection, "MaxRate");
  2609.   maintab->m_option5.m_maxconn =  MyGetProfileString(path,strSection, "MaxConn");
  2610.   maintab->m_option5.m_maxlinks = MyGetProfileString(path,strSection, "MaxLinks");
  2611.   
  2612.   // 7
  2613.   maintab->m_option7.m_url2 = MyGetProfileString(path,strSection, "WildCardFilters","+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*");
  2614.   
  2615.   // 10
  2616.   maintab->m_option10.m_proxy   = MyGetProfileString(path,strSection, "Proxy");
  2617.   maintab->m_option10.m_port    = MyGetProfileString(path,strSection, "Port");
  2618.   maintab->m_option10.m_ftpprox = MyGetProfileInt(path,strSection, "UseHTTPProxyForFTP",1);
  2619.   //
  2620.   maintab->m_option5.m_depth    = MyGetProfileString(path,strSection, "Depth");
  2621.   maintab->m_option5.m_depth2   = MyGetProfileString(path,strSection, "ExtDepth");
  2622.   
  2623.   // 11
  2624.   maintab->m_option11.m_ext1   = MyGetProfileString(path,strSection, "MIMEDefsExt1", "php3,php,php2,asp,jsp,pl,cfm");
  2625.   maintab->m_option11.m_ext2   = MyGetProfileString(path,strSection, "MIMEDefsExt2");
  2626.   maintab->m_option11.m_ext3   = MyGetProfileString(path,strSection, "MIMEDefsExt3");
  2627.   maintab->m_option11.m_ext4   = MyGetProfileString(path,strSection, "MIMEDefsExt4");
  2628.   maintab->m_option11.m_ext5   = MyGetProfileString(path,strSection, "MIMEDefsExt5");
  2629.   maintab->m_option11.m_ext6   = MyGetProfileString(path,strSection, "MIMEDefsExt6");
  2630.   maintab->m_option11.m_ext7   = MyGetProfileString(path,strSection, "MIMEDefsExt7");
  2631.   maintab->m_option11.m_ext8   = MyGetProfileString(path,strSection, "MIMEDefsExt8");
  2632.   maintab->m_option11.m_mime1   = MyGetProfileString(path,strSection, "MIMEDefsMime1", "text/html");
  2633.   maintab->m_option11.m_mime2   = MyGetProfileString(path,strSection, "MIMEDefsMime2");
  2634.   maintab->m_option11.m_mime3   = MyGetProfileString(path,strSection, "MIMEDefsMime3");
  2635.   maintab->m_option11.m_mime4   = MyGetProfileString(path,strSection, "MIMEDefsMime4");
  2636.   maintab->m_option11.m_mime5   = MyGetProfileString(path,strSection, "MIMEDefsMime5");
  2637.   maintab->m_option11.m_mime6   = MyGetProfileString(path,strSection, "MIMEDefsMime6");
  2638.   maintab->m_option11.m_mime7   = MyGetProfileString(path,strSection, "MIMEDefsMime7");
  2639.   maintab->m_option11.m_mime8   = MyGetProfileString(path,strSection, "MIMEDefsMime8");
  2640.   
  2641.   
  2642.   //st = MyGetProfileString(path,strSection,"WildCardFilters");
  2643.   //strcpybuff(buff_filtres,st);
  2644.   
  2645.   // liens, jokers etc. si mirror merge
  2646.   if (!(path.IsEmpty())) {
  2647.     if (dialog1->m_hWnd == NULL) {    // pas initialisÈ
  2648.       //dialog1->m_depth  = MyGetProfileString(path,strSection,"CurrentDepth");
  2649.       dialog1->m_urls     = MyGetProfileString(path,strSection,"CurrentUrl");
  2650.       dialog1->m_todo     = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2651.       dialog1->m_filelist = MyGetProfileString(path,strSection,"CurrentURLList");
  2652.       /*
  2653.       if (load_path) {
  2654.       CString st;
  2655.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2656.       if (st != "")
  2657.       dialog1->m_pathlog = st;
  2658.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2659.       if (st != "")
  2660.       dialog1->m_pathmir = st;
  2661.       }
  2662.       */
  2663.     } else {
  2664.       //st = MyGetProfileString(path,strSection,"CurrentDepth");
  2665.       //dialog1->SetDlgItemText(IDC_depth,st);
  2666.       st = MyGetProfileString(path,strSection,"CurrentUrl");
  2667.       dialog1->SetDlgItemText(IDC_URL,st);
  2668.       int n = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2669.       dialog1->m_ctl_todo.SetCurSel(n);
  2670.       st = MyGetProfileString(path,strSection,"CurrentURLList");
  2671.       dialog1->SetDlgItemText(IDC_filelist,st);
  2672.       /*
  2673.       if (load_path) {
  2674.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2675.       if (st != "")
  2676.       dialog1->SetDlgItemText(IDC_pathlog,st);
  2677.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2678.       if (st != "")
  2679.       dialog1->SetDlgItemText(IDC_pthmir,st);
  2680.       }
  2681.       */
  2682.       dialog1->Refresh();
  2683.     }
  2684.   }
  2685.   
  2686. }
  2687.  
  2688. // Initialisation du RAS
  2689. void InitRAS() {
  2690. #if USE_RAS
  2691.   if (!LibRas) {
  2692.     LibRas=new CDynamicRAS();
  2693.     if (LibRas->IsRASLoaded()) 
  2694.       LibRasUse=1;
  2695.     else
  2696.       LibRasUse=0;
  2697.   }
  2698. #endif
  2699. }
  2700.  
  2701. // Reconstruire index gÈnÈral!
  2702. void Build_TopIndex(BOOL check_empty) {
  2703.   CWaitCursor wait;
  2704.  
  2705.   //if (toptemplate_header && toptemplate_body && toptemplate_footer) {
  2706.   {
  2707.     char path[HTS_URLMAXSIZE*2];
  2708.     strcpybuff(path,CShellApp_app->end_path);
  2709.  
  2710.     /* Build top index */
  2711.     hts_buildtopindex(path, "");
  2712.  
  2713.     /* Check empty dirs and build .whtt */
  2714.     // FILE* fpo=fopen(fconcat(path,"/index.html"),"wb");
  2715.     //if (fpo) {
  2716.     {
  2717.       // verif_backblue(path);    // gÈnÈrer gif
  2718.       //
  2719.       // Header
  2720.       //fprintf(fpo,toptemplate_header,
  2721.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2722.       //  );
  2723.       // chargement de la liste
  2724.       WIN32_FIND_DATA find;
  2725.       HANDLE h = FindFirstFile(CShellApp_app->end_path+"*.*",&find);
  2726.       if (h != INVALID_HANDLE_VALUE) {
  2727.         CString to_delete="";
  2728.         do {
  2729.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  2730.             if (strcmp(find.cFileName,".."))
  2731.               if (strcmp(find.cFileName,"."))
  2732.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2733.                   int r;
  2734.                   r=CheckDirInfo(CShellApp_app->end_path+find.cFileName);
  2735.                   if ((r>=0) && (r<=3)) {       /* vide, fichiers vides etc */
  2736.                     to_delete+=(CShellApp_app->end_path+find.cFileName+"\n");
  2737.                   } else {      /* non vide */
  2738.                     char iname[HTS_URLMAXSIZE*2],iname2[HTS_URLMAXSIZE*2];
  2739.                     strcpybuff(iname,CShellApp_app->end_path);
  2740.                     strcatbuff(iname,find.cFileName);
  2741.                     strcatbuff(iname,"\\");
  2742.                     strcpybuff(iname2,iname);
  2743.                     strcatbuff(iname,"index.html");
  2744.                     strcatbuff(iname2,"\\hts-cache\\winprofile.ini");
  2745.                     if (fexist(iname)) {
  2746.                       char hname[HTS_URLMAXSIZE*2];
  2747.                       strcpybuff(hname,find.cFileName);
  2748.                       escape_check_url(hname);
  2749.                       // Body
  2750.                       //fprintf(fpo,toptemplate_body,
  2751.                       //  hname,
  2752.                       //  find.cFileName
  2753.                       //  );
  2754.                     }
  2755.                     
  2756.                     if ((fexist(iname)) || (fexist(iname2)) ) {
  2757.                       // vÈrifier existence de .whtt
  2758.                       strcpybuff(iname,CShellApp_app->end_path);
  2759.                       strcatbuff(iname,find.cFileName);
  2760.                       strcatbuff(iname,".whtt");
  2761.                       if (!fexist(iname)) {
  2762.                         FILE* fp=fopen(iname,"wb");
  2763.                         if (fp) fclose(fp);
  2764.                       }
  2765.                       
  2766.                     }
  2767.                   }
  2768.                 } else {    /* effacer .whtt qui ne pointent vers rien */
  2769.                   CString iname=CShellApp_app->end_path+find.cFileName;
  2770.                   if (iname.Right(5).CompareNoCase(".whtt")==0) {
  2771.                     CString rname=iname.Left(iname.GetLength()-5)+"\\index.html";
  2772.                     CString rname2=iname.Left(iname.GetLength()-5)+"\\hts-cache\\winprofile.ini";
  2773.                     if ( (!fexist((char*)LPCTSTR(rname))) && (!fexist((char*)LPCTSTR(rname2))) ) {
  2774.                       remove(iname);
  2775.                     }
  2776.                   }
  2777.                 }
  2778.         } while(FindNextFile(h,&find));
  2779.         FindClose(h);
  2780.         if (check_empty) {
  2781.           while(to_delete.GetLength()>0) {
  2782.             int pos=to_delete.Find('\n');
  2783.             if (pos) {
  2784.               CString path=to_delete.Left(pos);
  2785.               to_delete=to_delete.Mid(pos+1);
  2786.               CString str;
  2787.               str.Format(LANG_DELETEEMPTYCONF,path);
  2788.               if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) {
  2789.                 /* Èliminer au besoin le .whtt */
  2790.                 DeleteFile(path+".whtt");
  2791.                 if (!RemoveEmptyDir(path))
  2792.                   AfxMessageBox(LANG_ERRORDEL);
  2793.               }
  2794.             } else
  2795.               to_delete="";
  2796.           }
  2797.         }
  2798.       }
  2799.       // Footer
  2800.       //fprintf(fpo,toptemplate_footer,
  2801.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2802.       //  );
  2803.       //fclose(fpo);
  2804.     }
  2805.     
  2806.   }
  2807.  
  2808.   /*
  2809.   if (toptemplate_header)
  2810.     freet(toptemplate_header);
  2811.   if (toptemplate_body)
  2812.     freet(toptemplate_body);
  2813.   if (toptemplate_footer)
  2814.     freet(toptemplate_footer);
  2815.   */
  2816. }
  2817.  
  2818. /*
  2819. -1 : error
  2820. 0 : directory is empty
  2821. 1 : empty directories inside
  2822. 2 : empty files inside
  2823. 3 : 1 + 2
  2824. 4 : not empty
  2825. */
  2826. int CheckDirInfo(CString path) {
  2827.   CWaitCursor wait;
  2828.   
  2829.   if (path.Right(1)!="\\")
  2830.     path+="\\";
  2831.   
  2832.   // Pour FindFirstFile/FindNextFile
  2833.   WIN32_FIND_DATA find;
  2834.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2835.   
  2836.   // accessible
  2837.   if (h!=INVALID_HANDLE_VALUE) {
  2838.     int return_code=0;
  2839.     do {
  2840.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2841.         if (strcmp(find.cFileName,"..")) {
  2842.           if (strcmp(find.cFileName,".")) {
  2843.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2844.               return_code|=1;
  2845.               int r=CheckDirInfo(path+find.cFileName);
  2846.               if (r==4)
  2847.                 return_code=4;
  2848.               else
  2849.                 return_code|=r;
  2850.             } else {
  2851.               return_code|=2;
  2852.               if ((find.nFileSizeLow) || (find.nFileSizeHigh))
  2853.                 return_code=4;
  2854.             }
  2855.           }
  2856.         }
  2857.       }
  2858.     } while(FindNextFile(h,&find) && !((return_code & 4)) );
  2859.     FindClose(h);
  2860.     return return_code;
  2861.   } else
  2862.     return -1;
  2863. }
  2864.  
  2865. /*
  2866. Remove Empty Dir
  2867. */
  2868. BOOL RemoveEmptyDir(CString path) {
  2869.   CWaitCursor wait;
  2870.   
  2871.   SetCurrentDirectory("C:\\");
  2872.   
  2873.   if (path.Right(1)!="\\")
  2874.     path+="\\";
  2875.   
  2876.   // Pour FindFirstFile/FindNextFile
  2877.   WIN32_FIND_DATA find;
  2878.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2879.   
  2880.   // accessible
  2881.   if (h!=INVALID_HANDLE_VALUE) {
  2882.     do {
  2883.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2884.         if (strcmp(find.cFileName,"..")) {
  2885.           if (strcmp(find.cFileName,".")) {
  2886.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2887.               if (!RemoveEmptyDir(path+find.cFileName)) {
  2888.                 FindClose(h);
  2889.                 return 0;
  2890.               }
  2891.             } else {
  2892.               if ((!find.nFileSizeLow) && (!find.nFileSizeHigh))
  2893.                 if (!DeleteFile(path+find.cFileName)) {
  2894.                   FindClose(h);
  2895.                   return 0;
  2896.                 }
  2897.             }
  2898.           }
  2899.         }
  2900.       }
  2901.     } while(FindNextFile(h,&find));
  2902.     FindClose(h);
  2903.     
  2904.     SetCurrentDirectory("C:\\");
  2905.     return RemoveDirectory(path.Left(path.GetLength()-1));
  2906.   } else
  2907.     return 0;
  2908.   return TRUE;
  2909. }
  2910.